PHP allows access to non-static methods using ClassName:: But Why does it throw error when accessing non-static properties using ClassName::?
Class Names can access non-static methods but cannot access non-static properties
Code
<?php
class BaseClass {
public $x = 10;
public function __construct() {
echo "BaseClass constructor". "<br>";
}
}
class SubClass extends BaseClass {
public function __construct() {
BaseClass::__construct();
echo "SubClass constructor" . "<br>";
print parent::$x;
}
}
(new SubClass());
?>