Php Wordpress主题错误“;致命错误:无法重新分配自动全局变量“U POST”;

Php Wordpress主题错误“;致命错误:无法重新分配自动全局变量“U POST”;,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,这个主题有个错误, 当我尝试激活它时,它会出现 ( ! ) SCREAM: Error suppression ignored for ( ! ) Fatal error: Cannot re-assign auto-global variable _POST in C:\wamp\www\web\wp-content\themes\soundrock\functions.php on line 48 Call Stack # Time Memory Function Loca

这个主题有个错误, 当我尝试激活它时,它会出现

( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Cannot re-assign auto-global variable _POST in C:\wamp\www\web\wp-content\themes\soundrock\functions.php on line 48
Call Stack
#   Time    Memory  Function    Location
1   0.0014  364560  {main}( )   ..\themes.php:0
2   0.0043  433520  require_once( 'C:\wamp\www\web\wp-admin\admin.php' )    ..\themes.php:10
3   0.0048  451648  require_once( 'C:\wamp\www\web\wp-load.php' )   ..\admin.php:30
4   0.0052  463256  require_once( 'C:\wamp\www\web\wp-config.php' ) ..\wp-load.php:29
5   0.0061  553312  require_once( 'C:\wamp\www\web\wp-settings.php' )   ..\wp-config.php:90
所以在functions.php的第48行,我删除了这段代码,然后主题开始工作,但我想知道为什么它会抛出错误

function events_meta_save($_POST, $post_id) {
    global $wpdb;
    if ( empty($_POST["event_social_sharing"]) ) $_POST["event_social_sharing"] = "";
    if ( empty($_POST["event_start_time"]) ) $_POST["event_start_time"] = "";
    if ( empty($_POST["event_end_time"]) ) $_POST["event_end_time"] = "";
    if ( empty($_POST["event_all_day"]) ) $_POST["event_all_day"] = "";
    if ( empty($_POST["event_booking_url"]) ) $_POST["event_booking_url"] = "";
    if ( empty($_POST["event_address"]) ) $_POST["event_address"] = "";
        $sxe = new SimpleXMLElement("<event></event>");
            $sxe->addChild('event_social_sharing', $_POST["event_social_sharing"] );
            $sxe->addChild('event_start_time', $_POST["event_start_time"] );
            $sxe->addChild('event_end_time', $_POST["event_end_time"] );
            $sxe->addChild('event_all_day', $_POST["event_all_day"] );
            $sxe->addChild('event_booking_url', $_POST["event_booking_url"] );
            $sxe->addChild('event_address', $_POST["event_address"] );
                $sxe = save_layout_xml($sxe);
        update_post_meta( $post_id, 'cs_event_meta', $sxe->asXML() );
}
function events\u meta\u save($\u POST,$POST\u id){
全球$wpdb;
如果(空($发布[“事件\社交\共享”]))$发布[“事件\社交\共享”]=”;
如果(空($发布[“事件\开始\时间]))$发布[“事件\开始\时间”]=”;
如果(空($发布[“事件\结束\时间])$发布[“事件\结束\时间”]=”;
如果(空($_POST[“event_all_day”])$_POST[“event_all_day”]=”;
如果(空($\u POST[“事件\预订\ url”])$\u POST[“事件\预订\ url”]=”;
如果(空($_POST[“事件地址”]))$_POST[“事件地址”]=”;
$sxe=新的SimpleXMLElement(“”);
$sxe->addChild('event\u social\u sharing',$\u POST[“event\u social\u sharing]”);
$sxe->addChild('event\u start\u time',$\u POST[“event\u start\u time”]);
$sxe->addChild('event\u end\u time',$\u POST[“event\u end\u time”]);
$sxe->addChild('event\u all\u day',$\u POST[“event\u all\u day]”);
$sxe->addChild('event\u booking\u url',$\u POST[“event\u booking\u url]”);
$sxe->addChild('event\u address',$\u POST[“event\u address]”);
$sxe=保存布局xml($sxe);
更新发布元数据($post\u id,'cs\u event\u meta',$sxe->asXML());
}
更换

function events_meta_save($_POST, $post_id) {
    global $wpdb;
    if ( empty($_POST["event_social_sharing"]) ) $_POST["event_social_sharing"] = "";
    ....
    ....

不要忘记将条件中的所有
$\u POST
替换为
$\u my\u POST
或您喜欢的任何其他名称

原因,如其他答案所述:

不能将$\u POST用作函数/方法参数

。这样做会尝试在符号表中重新分配变量。
将此视为语言的已保存关键字。将其放在函数签名中就像使用该语言的关键字作为变量名来定义新变量。

@snjflame,您不需要使用
$\u POST
作为函数的参数,因为它是一个超全局变量。您不能重新定义
$\u POST
变量;您需要在函数开头为
$\u POST
变量定义一个“
处理程序”
,并在下面使用它

例如:

<?php
    function events_meta_save( $post_id ) {
        global $wpdb;
        $post = $_POST;
        if ( empty($post["event_social_sharing"]) ) $post["event_social_sharing"] = "";
        if ( empty($post["event_start_time"]) ) $post["event_start_time"] = "";
        if ( empty($post["event_end_time"]) ) $post["event_end_time"] = "";
        if ( empty($post["event_all_day"]) ) $post["event_all_day"] = "";
        if ( empty($post["event_booking_url"]) ) $post["event_booking_url"] = "";
        if ( empty($post["event_address"]) ) $post["event_address"] = "";
        $sxe = new SimpleXMLElement("<event></event>");
            $sxe->addChild('event_social_sharing', $post["event_social_sharing"] );
            $sxe->addChild('event_start_time', $post["event_start_time"] );
            $sxe->addChild('event_end_time', $post["event_end_time"] );
            $sxe->addChild('event_all_day', $post["event_all_day"] );
            $sxe->addChild('event_booking_url', $post["event_booking_url"] );
            $sxe->addChild('event_address', $post["event_address"] );
        $sxe = save_layout_xml($sxe);
        update_post_meta( $post_id, 'cs_event_meta', $sxe->asXML() );
    }
?>
addChild('event_social_sharing',$post[“event_social_sharing”);
$sxe->addChild('event_start_time',$post[“event_start_time”]);
$sxe->addChild('event_end_time',$post[“event_end_time”]);
$sxe->addChild('event\u all\u day',$post[“event\u all\u day]”);
$sxe->addChild('event\u booking\u url',$post[“event\u booking\u url]”);
$sxe->addChild('event_address',$post[“event_address]”);
$sxe=保存布局xml($sxe);
更新发布元数据($post\u id,'cs\u event\u meta',$sxe->asXML());
}
?>
<?php
    function events_meta_save( $post_id ) {
        global $wpdb;
        $post = $_POST;
        if ( empty($post["event_social_sharing"]) ) $post["event_social_sharing"] = "";
        if ( empty($post["event_start_time"]) ) $post["event_start_time"] = "";
        if ( empty($post["event_end_time"]) ) $post["event_end_time"] = "";
        if ( empty($post["event_all_day"]) ) $post["event_all_day"] = "";
        if ( empty($post["event_booking_url"]) ) $post["event_booking_url"] = "";
        if ( empty($post["event_address"]) ) $post["event_address"] = "";
        $sxe = new SimpleXMLElement("<event></event>");
            $sxe->addChild('event_social_sharing', $post["event_social_sharing"] );
            $sxe->addChild('event_start_time', $post["event_start_time"] );
            $sxe->addChild('event_end_time', $post["event_end_time"] );
            $sxe->addChild('event_all_day', $post["event_all_day"] );
            $sxe->addChild('event_booking_url', $post["event_booking_url"] );
            $sxe->addChild('event_address', $post["event_address"] );
        $sxe = save_layout_xml($sxe);
        update_post_meta( $post_id, 'cs_event_meta', $sxe->asXML() );
    }
?>