意外的 T_FUNCTION 与 php 5.2.17 但在 localhost 和 php 5.3.10 上很好 [英] unexpected T_FUNCTION with php 5.2.17 but fine on localhost and php 5.3.10

查看:12
本文介绍了意外的 T_FUNCTION 与 php 5.2.17 但在 localhost 和 php 5.3.10 上很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

The theme works fine on localhost (with MAMP) and there are also no errors on my own server which runs php version 5.3.10.

可能有什么问题或可以采取什么措施来解决此错误?

What can be wrong or what can be done to solve this error?

这是导致错误的行:

add_action('init', function() use($name, $args) {   

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

And the entire functions.php file looks like this:

<?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')
));

我对 php 真的很陌生,只将它用于 Wordpress 主题.非常感谢任何帮助.

I'm really new to php and only use it for Wordpress theming. Any help is really appreciated.

推荐答案

不能在低于 5.3 的 PHP 中有匿名函数

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.

这篇关于意外的 T_FUNCTION 与 php 5.2.17 但在 localhost 和 php 5.3.10 上很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆