Re: String passed to object constructor turning into aninstance of that object?

From: Date: Thu, 16 Dec 2010 22:21:17 +0000
Subject: Re: String passed to object constructor turning into aninstance of that object?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-310088@lists.php.net to get a copy of this message
Nathan Nobbe wrote:
Why not test for the type of $name at each point of interest in the SelectBoxOption constructor? If you're passing a string value to the constructor it almost has to be getting changed by the Tag constructor, right ? class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { var_dump(is_string($name));
     parent::Tag("option", $name);
var_dump(is_string($name));
Ah, that gives... well, it slightly alters the confusion. Using var_dump(is_string($name)) gives... two results? bool(true) bool(false) And dumping $name itself gives: string(8) "Abegweit" object(SelectBoxOption)#65 (5) { ["attributes"]=> array(1) { [0]=> object(TagAttribute)#66 (3) { ["name"]=> string(5) "value" ["value"]=> string(1) "4" ["hasValue"]=> bool(true) } } ["tagContent"]=> string(8) "Abegweit" ["tag"]=> string(6) "option" ["showEndTag"]=> bool(false) ["children"]=> array(0) { } } O_o Just to confirm, I checked a test instance of the site on CentOS 4, with PHP 4.3, and I get one "bool(true)" for each <option> - not two as is happening with PHP 5.2. -kgd (I haven't worked with PHP for quite a while, and I never really spent a lot of time getting deep into complex data structures and object hierarchies like this when I was using it. But this behaviour does NOT match what I know of passing values and object references around in any other language.)

« previous php.general (#310088) next »