3v4l.org

run code in 300+ PHP versions simultaneously
<?php class testClass { protected $config; public function getConfiguration() { $this->config = new section; } public function __get($name) { echo "magic method has been called, name is $name\n"; $method = "get".ucfirst($name); return method_exists($this, $method) ? $this->$method() : null; } public function test() { var_dump(empty($this->configuration->name)); var_dump($this->configuration); } } class section { protected $vars; public function __contstruct() { $this->vars = [ 'name' => 1, 'val' => 2 ]; } public function __get($name) { return isset($this->vars[$name]) ? $this->vars[$name] : null; } public function __isset($name) { return isset($this->vars[$name]); } } $a = new testClass; $a -> test();
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
magic method has been called, name is configuration bool(true) magic method has been called, name is configuration NULL

preferences:
271.3 ms | 404 KiB | 291 Q