Re: In php 8.0: unable to distinguish between instance variable beingnull and unset

[email protected] (Emiel Mols)
Newsgroups php.general
Message-ID <CAF5w505_n+R7mSKBZkmxfmm+Nv+_xqadX5+zWLYHER3ao-wU9A@mail.gmail.com>
Was missing a ? there. Updated case at
https://3v4l.org/rH4p4

On Sat, 4 Sep 2021 at 21:30, Ben Ramsey <[email protected]> wrote:

> 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
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.