Hello Christian, Stas,

Tuesday, May 13, 2008, 4:08:09 PM, you wrote:

> Marcus Boerger wrote:
>>> unset($o_Foo->bar);
>>> echo $o_Foo->bar;
>> ?>>
>> 
>>> outputs ...
>>> Notice: Undefined property: foo::$bar in C:\- on line 13
>> 
>> At this point you found an error. Because this allows unset() to modify an
>> instance in a way that it nolonger adheres to its class that means at this
>> point the following is nolonger valid: $o_Foo is-a foo. And that is the
>> basic design rule we chose for PHP. Please file as a bug!

> So you are saying that
>         $o_Foo->bar = array(42);
> is ok when the class "expects" a string but
>         unset($o_Foo->bar);
> or (as as slight variation)
>         $o->Foo->bar = null;
> is not?

I Do not get the connection here? And since when can we 'expect' a string
only for a property?

My point is that an object should always have a property, whether it has
the value NULL or not doesn't matter at all. And actually unsetting a
property right now doesn't change much besides that it breaks inhereitance
rules and affects reflection (maybe, not tested). Becasue when a defined
property is unset() and that infact results in deletion than the property
information ist still present in the class. The next access to that
property now must not result in an error (not even E_NOTICE as even that
would be misleading, people would try to find the error in the class). And
anyway PHP happily recreates the property with value NULL if being
accessed. And if the property is not declared than PHP will simply create a
new property on access. This creation of undeclared properties does not
affect any inheritance rules and was decided on. This is what Sats meant
with what PHP allows beyond C++ and Java. Allowing anythign more breaks our
basic design principles.

> I'd ask not to change this behaviour as you'll just add another (IMHO
> bogus) restriction on how an object or class can be modified at runtime.
> An error possibly caused by this is already handled by the E_NOTICE
> message anyway.

> For comparison: Having to declare static class variables is a similar
> restriction which got in my way more often than it helped me.

> - Chris




Best regards,
 Marcus


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

Reply via email to