解析错误:语法错误,意外'$ _POST'(T_VARIABLE)

时间:2015-06-11 06:37:02

标签: php ajax

  

解析错误:语法错误,意外的'$ _POST'(T_VARIABLE)   C:\ xampp3 \ htdocs中\ htdocsManagement \ ecms.src \ ecms.ajax \ ajax.handle.readData.php   在第8行

<?php
    header("Content-Type: application/json");
    require_once("../class.core.php");

    class ajaxReadData {
        private $mAnswer = array("isValid" => true);

        private $mType = $_POST["mType"];

        public function __construct() {
            global $workflowHandler;
            global $systemHandler;

            echo $this->mType;
            $this->getResult();
        }

        private function getResult() {
            echo json_encode($this->mAnswer);
        }
    } (new ajaxReadData());
?>

错误是什么?

1 个答案:

答案 0 :(得分:0)

问题在于private $mType = $_POST["mType"];

  

此成员声明可能包含初始化,但此初始化必须是常量值 - 也就是说,它必须能够在编译时进行评估,并且不能依赖于运行时信息为了进行评估。

$_POST["mType"]是运行时信息。相反,将初始化移动到构造函数,如下所示:

private $mType;

public function __construct() {
   global $workflowHandler;
   global $systemHandler;

   // Initialize with run-time data here
   $this->mType = $_POST["mType"];

   echo $this->mType;
   $this->getResult();
}