On 5/26/2016 12:39 PM, Rowan Collins wrote: > On 26/05/2016 11:16, Fleshgrinder wrote: >> $o = (object) ['x' => null]; >> var_dump(isset($a->x)); // false >> var_dump(property_exists($a, 'x')); // true > > Apart from a typo in your example (you change from $o to $a), this is > already the current behaviour, and always has been: https://3v4l.org/NeqGl > > isset() is really very simple: if the thing your accessing would give > you the value null, it returns false, otherwise it returns true. > > Regards,
Now I feel stupid but I guess I got lost myself. :P This means it is even simpler, we just have to add the E_NOTICE and be done with it. $g = new class { public $x; }; var_dump($g->x); // null + E_NOTICE Uninitialized var_dump(isset($g->x)); // false var_dump(property_exists($g, 'x')); // true var_dump(is_null($g->x)); // true + E_NOTICE Uninitialized var_dump($g->x == null); // true + E_NOTICE Uninitialized var_dump($g->x === null); // true + E_NOTICE Uninitialized This behavior would be true for all variations: class A { var $x; public $x; public int $x; public ?int $x; } No notice for the following: class A { var $x = null; public $x = null; public int $x = 0; public ?int $x = null; } -- Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature