Hello elephpants.

Currently PHP allows explicitly declared fields (eg public $foo = 10;) to
be removed entirely through unset (eg unset($obj->foo)).

Now that isn't really an issue as properties in php are currently untyped
and therefore nullable; at worst you would get a notice. But it would
become an issue with typed fields... that might get a second chance sooner
or later.

But regardless of that, it looks very strange to me that this is allowed
for fields that are explicitly declared. I think unset() should set the
field to null if it's declared in the class, and remove the field
altogether only if it was defined dynamically.

On the other hand, this is just one of many ways of hacking php that just
exist and we accept / don't care because we have faith in other people not
doing nasty stuff with our code. This might sound ironic it is actually not
:P

However, I am curious: what you think about this? Should PHP do something
in regard? Should this continue to work like it does now? Why do you feel
it should do the one or the other?

Reply via email to