在PHP中为什么不起作用

class GrandClass {
    public $data;
    public function __construct() {
        $this->someMethodInTheParentClass();
    }
    public function someMethodInTheParentClass() {
        $this->$data = 123456;
    }
}

class MyParent extends GrandClass{
    public function __construct() {
        parent::__construct();
    }
}

class Child extends MyParent {
    // public $data;
    public function __construct() {
        parent::__construct();
    }
    public function getData() {
        return $this->data; 
    }
}

$a = new Child();
var_dump($a->getData());

PHP Notice: Undefined variable: data in D:\test.php on line 7

PHP Fatal error: Cannot access empty property in D:\test.php on line 7

update your function someMethodInTheParentClass with below using $this->data = 123456;

 public function someMethodInTheParentClass() {
        $this->data = 123456;
    }
Use  `$this->data = 123456; `instead of`  $this->$data = 123456;` in below function

public function someMethodInTheParentClass() {
        $this->data = 123456;
}

Constructors in MyParent and Child classes are unnecessary.