使用php 5.2.17意外的T_FUNCTION但在localhost和php 5.3.10上很好

Nie*_*lon 3 php wordpress

将我的Wordpress文件上传到运行php版本5.2.17的服务器后,我收到了一个意外的T_FUNCTION php错误.

主题在localhost(使用MAMP)上工作正常,并且我自己的服务器上运行php版本5.3.10也没有错误.

可能出现什么问题或者可以采取哪些措施来解决这个错误?

这是导致错误的行:

add_action('init', function() use($name, $args) {   
Run Code Online (Sandbox Code Playgroud)

整个functions.php文件如下所示:

<?php 

/* Add Post Type */
function add_post_type($name, $args = array() ) {   
    if ( !isset($name) ) return;

    $name = strtolower(str_replace(' ', '_', $name));

    add_action('init', function() use($name, $args) {   
        $args = array_merge(
            array(
                'label' => 'Members ' . ucwords($name) . '',
                'labels' => array('add_new_item' => "Add New $name"),
                'singular_name' => $name,
                'public' => true,
                'supports' => array('title', 'editor', 'comments'),
            ),
            $args
        );

        register_post_type( $name, $args);
    });
}


add_post_type('Netherlands', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));


add_post_type('Belgium', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('Germany', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('France', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('United-Kingdom', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('Ireland', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('Spain', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('Portugal', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));

    add_post_type('Italy', array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments')
));
Run Code Online (Sandbox Code Playgroud)

我是php的新手,只用于Wordpress主题.任何帮助都非常感谢.

Nea*_*eal 7

不能在PHP中使用小于5.3的匿名函数

修改您的代码,使其不涉及匿名函数,它应该在您的旧服务器上工作.