WP & PHP7

chris Blog ,
0

Recently I helped a friend update his server to PHP 7. Every thing went pretty smoothly, well at least until he tried to view his Word Press site. The site was working ok but one of his home made plugins was not. He was receiving this error Parse error: syntax error, unexpected ‘new’ (T_NEW) .
So first things first, lets look at the plugin line number. Here was the code.

$GLOBALS[‘wp_the_query’] =& new WP_Query();

OK, looks like solid PHP WP code. So I then reviewed the changes to PHP7. After some serious digging I found that some changes were made in PHP 7 that don’t allow you to assign classes with a & symbol anymore.

So I just removed that & symbol so the line of code now looked like this.

$GLOBALS[‘wp_the_query’] = new WP_Query();

I then ran a quick search on the rest of the files in the plugin looking for =& and made the necessary changes in those files as well. The plugin was once again working.

I recommend updating to PHP7 it is much faster that 5.6. Found that running WP 4.6.1 on PHP7 is fine. No major problems with core system, just a couple with older plugins.

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you ready to take your company to the next level?

Yes, Contact Me!