3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace GetObjectVars; // use function PHPStan\Testing\assertType; function assertType($_, $a) {var_dump($a);} class Base { public int $a = 1; public string $b = ''; protected string $c = ''; private bool $d = false; public function getVars(): void { assertType('array{a: int, b: string, c: string, d: bool}', get_object_vars($this)); } } class Extended extends Base { public string $foo = 'foo'; public function getExtendedVars(): void { assertType('array{a: int, b: string, c: string}', get_object_vars($this)); } } (new Base)->getVars(); (new Extended)->getVars(); (new Extended)->getExtendedVars();
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array(4) { ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> string(0) "" ["d"]=> bool(false) } array(5) { ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> string(0) "" ["d"]=> bool(false) ["foo"]=> string(3) "foo" } array(4) { ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> string(0) "" ["foo"]=> string(3) "foo" }
Output for 8.0.1 - 8.0.30
array(4) { ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> string(0) "" ["d"]=> bool(false) } array(5) { ["foo"]=> string(3) "foo" ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> string(0) "" ["d"]=> bool(false) } array(4) { ["foo"]=> string(3) "foo" ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> string(0) "" }

preferences:
126.7 ms | 408 KiB | 5 Q