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

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

 



Nathan Nobbe wrote:
 2. try modifying Tag & SelectBoxOption to have __construct() instead of
Tag() & SelectBoxOption(), then call parent::__construct() from inside
of SelectBoxOption::__construct(); see if that clears up your problem
under
5.2 (read: this will only be a partial solution as it only addresses one
child of Tag).

Mmm.  I hoped this would help, but all it seems to have done was cascade
errors across the rest of Tag's object children.  :(


to be expected, but did it fix the problem w/ SelectBoxOption?

I'm not sure, but I don't think so; the original symptom was "Object of class SelectBoxOption could not be converted to string" - the original code didn't include a toString() method in SelectBoxOption, and since the code works on an older PHP, it must be using the parent object's toString(). (Which some children of Tag do explicitly, but SelectBoxOption doesn't for whatever reason.)

In trying to add the toString() method, I found that the calls used by other tags to retrieve the HTML tag name, value, etc weren't working. So I looked up at the constructor to see if the pieces passed in were getting passed and stored correctly - and quite obviously they're not ($name mutates into what looks like an array with a string at [0] and something closely resembling what the whole object instance *should* be at [1], and $value just seems to disappear).

Putting aside actually fixing the constructor correctly, after a bit of poking I found that $this->tagContent->..... works to retrieve the data and actually output the <option> tag correctly.

var_dump tells me that the real data is actually in there... it's "just" not instantiated correctly. $name apparently arrives at the constructor for SelectOptionBox like this:

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) {
  }
}

I'll try converting all of the constructors to your recommendation as
above, but given that the problem is only happening with this one class, I'm
not sure that will do much.

hopefully that clears it up ..

Well, I ran out of "Call to undefined ParentClass::parentclass in path/to/file/for/subclass.php" errors (at least on the page I'm testing with).... but $name is still going in on the calling side as a string, and coming out as a funky array.

and hopefully you're using version control :D

Bah!  Real man never make mistaaake!

... ooops.  <g>

(I've got the live site, on the old server, as reference, plus the regular backups of that machine.)

-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