Unexpected "silent" type-cast with initialized but un-set members
| From: | Morten Fangel | Date: | Thu, 16 Feb 2006 11:32:48 +0000 |
| Subject: | Unexpected "silent" type-cast with initialized but un-set members | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-21877@lists.php.net to get a copy of this message | ||
Hi,
Look at the following example:
---
<?php
class Foo {
public $bar;
function __construct() {
$this->bar->baz = 'blah';
}
}
$foo = new Foo();
print_r($foo);
?>
--
It results in:
---
Foo Object
(
[bar] => stdClass Object
(
[baz] => blah
)
)
---
Foo->bar is never declared as anything but "public" and is therefor
"type-less" (is there a proper term for this?).
As soon as I try to assign Foo->bar->baz, then Foo->bar is cast to an
stdObject and the baz property is set.
This is pretty much what you would expect, but IMHO this should generate an
E_NOTICE because you are using a non-object as an object..
Is this just my opinion?
Morten Fangel // fangel