Re: Class Properties in Interfaces?
| From: | Christian Schneider | Date: | Tue, 13 May 2008 14:08:09 +0000 |
| Subject: | Re: Class Properties in Interfaces? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37627@lists.php.net to get a copy of this message | ||
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'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