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 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法