On 25/04/2022 12:24, Guilliam Xavier wrote:
Hi Rowan,

(...) Also, there's this non-standard class called
"stdClass", which unlike standard classes, you can read and write any
property you like without declaring it,

Better reordered "write and read" I think. Yes, like associative arrays,
stdClass is "dynamic" by design.

Indeed, and if that was the only exception, it would be reasonable; it's when you pile it on top of all the other rules that it starts making people sad.

and even if you use unset(),
you'll never get an error.

That's not true, e.g. given `$o = (object)['foo' => 1]; $o->bar = 2;` then
`unset($o->foo, $o->bar);`, trying to read `$o->foo` or `$o->bar` will both
cause an error (like for `$o->qux`); or I'm misunderstanding you?

You're right, I was mis-remembering; the RFC explicitly says that this will error.

Are you proposing to deprecate the implicit `= null` default initializer
for untyped properties?


Thanks for the recap. For untyped properties, that's the historical
behavior. For typed properties, that's explained in
*. What's the issue?

The issue is that for new users, saying "that's the historical behaviour, you just have to learn it" is not very helpful.

* "If a typed property is `unset()`, then it returns to the uninitialized
state. While we would love to remove support for the unsetting of
properties, this functionality is currently used for lazy initialization by
Doctrine, in combination with the functionality described in the following

I think both you and Mark misunderstood my point in bringing this up - I'm not complaining about the ability to call unset(), I'm complaining that it behaves differently depending how the property was declared.

Look at how the untyped property behaves in this example: https://3v4l.org/nClNs The property disappears from var_dump(), but is not actually deleted from the object, as seen by it still being private when assigned a new value. Given that we have the magic "uninitialized" state, and we're proposing to make reading an unset property an error, it would make more sense for it to show as '["untyped":"Foo":private] => uninitialized(mixed)'


Rowan Tommins

PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to