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

前端 未结 3 1518
无人及你
无人及你 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: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'; });
    

提交回复
热议问题