3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test { private $foo; protected $bar; public function toarray() { return get_object_vars($this); } } class inheritedTest extends test { private $baz; protected $baf; public function toarray() { return array_merge( get_object_vars($this), parent::toArray() ); } } $test=new Test(); $vars = $test->toarray(); //does acccess private, protected var_dump($vars); $itest= new inheritedTest(); $vars = $itest->toArray(); // does access protected but not private var_dump($vars);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(2) { ["foo"]=> NULL ["bar"]=> NULL } array(4) { ["bar"]=> NULL ["baz"]=> NULL ["baf"]=> NULL ["foo"]=> NULL }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(2) { ["foo"]=> NULL ["bar"]=> NULL } array(4) { ["baz"]=> NULL ["baf"]=> NULL ["bar"]=> NULL ["foo"]=> NULL }

preferences:
178.94 ms | 404 KiB | 387 Q