Re: In php 8.0: unable to distinguish between instance variable beingnull and unset
[email protected] (Ben Ramsey)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
Emiel Mols wrote on 9/3/21 07:08:
> Hello,
>
> Our codebase depends on distinguishing whether an instance variable is
> unset, or simply null:
>
> class C { public int $v = 123; }
> $x = new C; unset($x->v);
> $y = new C; $u->v = null;
>
> In php <8.0 we made this work with @array_key_exists($x, 'v'), which
> stopped working. isset($x->x) doesn't work, as it will return true for
> 'null' as well. property_exists($x, 'v') will always return true as long as
> the variable is declared: php-src here
> <https://github.com/php/php-src/blob/a13730c5e465b3c349a7970d15a49e4e132d4e07/Zend/zend_builtin_functions.c#L943>
> .
>
> Apart from using debug_zval_dump (too expensive), any hints? This feels
> like quite the oversight honestly :).
>
> Best,
>
> Emiel
>
If you use `public int $v`, there shouldn't be a way to set it `null`,
unless I'm missing something.
https://3v4l.org/nNDq4
Cheers,
Ben
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEObZBND2MEEsrFG3D+cOdwLlphUQFAmEzyR0ACgkQ+cOdwLlp hUSbShAAhM3bYdwUrompdWbc4YMdKAFviVkX++Lzaxekslc7RyKhT5HkJGhd0Gd6 hpEQqvgI2Os66ePtObUxiSLr9DuBvkX9mrevJawyT3DpdquhtBU9b7nrpvB91vR3 04TmbLmYK4ar9i9ynkYSp1SUTKSB6SrjYTD8AnMFxDiB8C0r6HQlxrYFEhC6KDUW l/9Kb2uWmAVW8bkb3WqPkMI4NwQLBJGBuOf4Xm6Rj4f85/FTbzGjZsYRPvnCpaO0 0Cvqe5qvC/E4wEMhKtnFHJ0EDruFzMb8zsJlT33MjrXKhWFE+AEU3TRTUtJfGUqo QiYbbZEbMcY8C0kIfdokdhBN6VUMrYTEYM+biVCZdUD031D7QbkwHiCuvuyjt4KT OG2qbL+QbOx68T4VLZywZJGZ8npiixojYFMihMrE3OG0th3P2kpt7bROQ4qDxEo1 MqgMZoa1q2oh2Uo2z3fc8z5EDT0Vpq4KwNSd6JyWXK570QlpgUUCzwAUDHzGZe8N vyh0qvqBJdGvgCKoJWMQICGPmPhgpSpU3jql76xbeGFWCc/gJy3gRmZogtPxWTxi Avwf1paVOpDPEf2O3B0XsF/mib97XJk2FUKKz7f1r3C4HsJV1cmx/Y2cYNZMLXsr M62xm90qVYmHYD+eogKLr8m4q/tbr70jU4vBMc0QbBMAzwqZMdg= =bUDa -----END PGP SIGNATURE-----