unexpected T_FUNCTION with php 5.2.17 but fine on localhost and php 5.3.10

前端 未结 3 1506
无人及你
无人及你 2021-01-20 06:49

I\"m getting an unexpected T_FUNCTION php error after uploading my Wordpress files to a server running php version 5.2.17.

The theme works fine on localhost (with MA

相关标签:
3条回答
  • 2021-01-20 07:22

    You cannot have anonymous functions in PHP less than 5.3

    Rework your code so that it does not involve anonymous functions and it should work on your older server.

    0 讨论(0)
  • 2021-01-20 07:26

    anonymous functions available from PHP 5.3.0

    0 讨论(0)
  • 2021-01-20 07:35

    add_action()'s second parameter is of type callback.

    Pre 5.3, this is usually a string representing a function:

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

    There are alternatives such as create_function and other syntaxes to use when dealing with objects.

    5.3 onward, anonymous functions are allowed:

    add_action('init', function() { echo 'init'; });
    
    0 讨论(0)
提交回复
热议问题