On Thu, Dec 16, 2010 at 2:29 PM, Kris Deugau <kdeu...@vianet.ca> wrote:
> Tommy Pham wrote: > >> class SelectBoxOption extends Tag { >>> function SelectBoxOption($name, $value, $selected=false) { >>> parent::Tag("option", $name); >>> $this->addAttribute("value", $value); >>> if($selected) { >>> $this->addAttribute("selected", '', false); >>> } >>> if ($name == "") { echo " missing name!<br>\n"; } >>> // else { print " name $name<br>\n"; } >>> if ($value == "") { echo " missing value!<br>\n"; } >>> } >>> >>> >>> will parse and execute, but: >>> - the page will contain "missing value!" for each <option> in the >>> <select> this is generating >>> - it will *not* contain "missing name!" >>> - the <option> tags in the final output don't have content or value >>> (they should have both). >>> >>> If I uncomment that else, I get: >>> >>> >>> adding option <name1> with <value1> >>> name <value1> >>> >>> Catchable fatal error: Object of class SelectBoxOption could not be >>> converted to string in >>> <webroot>/includes/classes/core/display/form/input/SelectBoxOption.php >>> on line 12 >>> >> > What's the actual line #12 in the file SelectBoxOption.php? The >> SelectBoxOption code you presented has 11 lines unless it's a CNP error. >> > > Whups, thought I noted that. I trimmed a couple of blank lines; line 12 > in the file is that print in the else. > > I found trying to print $name triggers the same error anywhere in that > function, too; as I noted further down it seems the string that's passed in > is getting mutated into an object. (Whose missing toString function is what > led me here - but it works fine in PHP 4.3...) 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)); .. } -nathan