Skip to main content
added 170 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

PHP 5.2 is very old, as is 5.3, both of you should upgrade. Especially your client on 5.2. Aside from major security fixes and massive performance gains, PHP 5PHP 5.3 introduced closures and anonymous functions, e.3 introduced closuresg.:

$myfunctionadd_action( ='init', function () {
    echo 'hello';
} );

The above code is valid in PHP 5.3, and will generate syntax errors in 5.2, which is why your code, which uses an anonymous function, fails on your clients server.

For your code to be 5.2 compatible, you will need to define the function separately and pass in its name rather than defining it in place.

function myfunction() {
    echo 'hello';
}
add_action( 'init', 'myfunction' );

However, instead, I strongly recommend you both update to PHP 5.5 for security reasons or find a host with at least PHP 5.4. At the time of writing PHP 5.6 is the latest version, and PHP 5.2, and 5.3 are no longer supported or maintained.

Sidenote: Your code uses an anonymous functionanonymous function in a filter, which can be troublesome to debug and to remove. e.g. what do you pass into remove_action if the function has no name?

PHP 5.2 is very old, as is 5.3, both of you should upgrade. Especially your client on 5.2. Aside from major security fixes and massive performance gains, PHP 5.3 introduced closures:

$myfunction = function () {
    echo 'hello';
}

The above code is valid in PHP 5.3, and will generate syntax errors in 5.2.

For your code to be 5.2 compatible, you will need to define the function separately and pass in its name rather than defining it in place.

I strongly recommend you both update to PHP 5.5 for security reasons or find a host with at least PHP 5.4. At the time of writing PHP 5.6 is the latest version, and PHP 5.2, and 5.3 are no longer supported or maintained.

Sidenote: Your code uses an anonymous function in a filter, which can be troublesome to debug and to remove. e.g. what do you pass into remove_action if the function has no name?

PHP 5.2 is very old, as is 5.3, both of you should upgrade. Especially your client on 5.2. Aside from major security fixes and massive performance gains, PHP 5.3 introduced closures and anonymous functions, e.g.:

add_action( 'init', function () {
    echo 'hello';
} );

The above code is valid in PHP 5.3, and will generate syntax errors in 5.2, which is why your code, which uses an anonymous function, fails on your clients server.

For your code to be 5.2 compatible, you will need to define the function separately and pass in its name rather than defining it in place.

function myfunction() {
    echo 'hello';
}
add_action( 'init', 'myfunction' );

However, instead, I strongly recommend you both update to PHP 5.5 for security reasons or find a host with at least PHP 5.4. At the time of writing PHP 5.6 is the latest version, and PHP 5.2, and 5.3 are no longer supported or maintained.

Sidenote: Your code uses an anonymous function in a filter, which can be troublesome to debug and to remove. e.g. what do you pass into remove_action if the function has no name?

Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

PHP 5.2 is very old, as is 5.3, both of you should upgrade. Especially your client on 5.2. Aside from major security fixes and massive performance gains, PHP 5.3 introduced closures:

$myfunction = function () {
    echo 'hello';
}

The above code is valid in PHP 5.3, and will generate syntax errors in 5.2.

For your code to be 5.2 compatible, you will need to define the function separately and pass in its name rather than defining it in place.

I strongly recommend you both update to PHP 5.5 for security reasons or find a host with at least PHP 5.4. At the time of writing PHP 5.6 is the latest version, and PHP 5.2, and 5.3 are no longer supported or maintained.

Sidenote: Your code uses an anonymous function in a filter, which can be troublesome to debug and to remove. e.g. what do you pass into remove_action if the function has no name?