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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 "&nbsp;&nbsp;&nbsp;missing name!<br>\n"; }
//  else { print "&nbsp;&nbsp;&nbsp;name $name<br>\n"; }
if ($value == "") { echo "&nbsp;&nbsp;&nbsp;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...)

-kgd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux