On 25/02/2025 21:13, tight.fork3...@fastmail.com wrote:
Hello! I started GitHub issue requesting that property hooks be allowed to be 
`unset()`:https://github.com/php/php-src/issues/17922

While discussing in the issue it was suggested I pitch this to the mailing 
list, so here I am.


Place me firmly in the "unset() is already weird enough" camp.

I actually started writing an RFC to rationalise some of this behaviour, but gave up because it's such a mess.

Here are some of the things that might happen as a result of unset($foo->bar):

* Nothing at all, because unsetting a non-existent property isn't even a Warning * A dynamic property (not declared, but created because it was assigned a value) is deleted without trace * A property declared with no type becomes "undefined", and appears to be deleted (e.g. disappears from var_dump) ... * ... but retains its visibility (e.g. you'll still get an error writing to it from outside the class if it's private) * A property declared *with* a type (even if that type is "mixed") instead becomes "uninitialized" - it still appears in var_dump, and accessing it is an Error, instead of a Warning
* An __unset() handler might be called ...
* ... even if the property is declared, but is currently "undefined" or "uninitialized" ... * ... and that handler could do absolutely anything, including throwing an exception

If we allow a hooked property to directly "unset" the backing value, what *exactly* will it do? And what if it's a virtual property, so there is nothing to unset? If we add an "unset" hook, what's the default behaviour if one isn't defined?

I think it's one of those features that sounds simple when you look at a single use case, but actually specify the behaviour in all cases is going to be a lot of work.

--
Rowan Tommins
[IMSoP]

Reply via email to