What are the differences between PHP 5.3 and 5.4?

I am running PHP 5.3.15 (apache / php / mysql user stack on OSX) locally and have the following code that works fine:

$my_closure = function($something, $other) use (&$foo, $bar) { // watcha doin'? ... stuff. }; $my_closure('hello', array('one', 'two')); 

The employee uses MAMP with PHP 5.4.x and receives the error message “Function name must be a string” when closing is called ( $my_closure(...); ).

I can get around this with call_user_func() or call_user_func_array() , but I want to know why this code no longer works on 5.4.x. I think this is either a 5.4.x change or a problem with MAMP (in my experience, even more likely!).

There is a couple of php.net related in php.net that discusses the inability to use the called array in the same way I use closure. The error notes confirm that what I am doing works fine in 5.3, and also mentions the implementation of the functionality of the called array in 5.4; perhaps the implementation led to a regression error? Any details / suggestions would be appreciated.

And yes, I would love to use Vagrant for everyone on the team to have the same environments, but, alas, not cubes.

+4
source share
2 answers

Let your friend double-check that he is working 5.4. Your syntax is great for 5.3 and 5.4 (and I suppose any future version of PHP)

You can test your code in PHP 5.4 here (run echo phpversion(); to really confirm this is 5.4). As you will see, this does not cause any errors.

0
source

I also tried your code here and it works great in PHP5.4.

Do you have the option to activate eAccelerator with PHP5.4 in your Mamp configuration? EAccelerator caching software ships with Mamp versions for PHP up to PHP5.5. I suggest disabling eAccelerator as another developer in this article . The article claims that eAccelerator simply did not cope with all the changes that PHP experienced. Another user also encountered the same problem when using PHP5.4 with eAccelerator; see here . And, Mamp no longer includes eAcclerator with PHP since PHP5.5.

0
source

Source: https://habr.com/ru/post/1498501/


All Articles