0

Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in C:\xampp3\htdocs\htdocsManagement\ecms.src\ecms.ajax\ajax.handle.readData.php on line 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());
?>

what is the error?

Saty
  • 22,443
  • 7
  • 33
  • 51
znailla
  • 1
  • 1
  • 1
  • 1
    You can't assign "dynamic" values in the class definition. You have to move it in the constructor or in another method. (e.g. `$this->mType = ...`) – Rizier123 Jun 11 '15 at 06:40

1 Answers1

0

The problem is with private $mType = $_POST["mType"];

This member declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

$_POST["mType"] is run-time information. Instead, move initialization to the constructor like so:

private $mType;

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

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

   echo $this->mType;
   $this->getResult();
}
Drakes
  • 23,254
  • 3
  • 51
  • 94