<?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();
You have javascript disabled. You will not be able to edit any code.