dongyi4170 2012-06-04 18:29
浏览 46
已采纳

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

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 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?

This is the line that causes the error:

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

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

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

  • 写回答

3条回答 默认 最新

  • dopq87915 2012-06-04 18:30
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址