Re: [PHP] String passed to object constructor turning into an instance of that object?
I've never used the old-style constructors, but perhaps the semantics of "parent::" changed and you need to instead use "$this->" as in $this->Tag("option", $name); That's a total guess. I don't have 5.2 handy to try it out, but both work in 5.3 using a simple example. Can you post the constructor of one of the Tag subclasses that work? Maybe we can find a common denominator. David
Re: [PHP] String passed to object constructor turning into an instance of that object?
On Thu, Dec 16, 2010 at 4:04 PM, Kris Deugau wrote: > Nathan Nobbe wrote: > >> probly something screwy going on w/ the old style of naming constructors. >> 2 >> things, >> >> 1. can you post the Tag constructor as it reads now? >> > > function Tag($tag='', $tagContent='') { > $this->tagContent = $tagContent; > $this->tag = $tag; > $this->showEndTag = false; > > $this->attributes = array(); > $this->children = array(); > > } > seems innocuous .. > > 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? > Copying the old constructor back in resolved that, but I'm not sure whether > that reintroduces the root problem. > Other objects derived from Tag seem to work just fine; I came into this > chunk of the code trying to find out why a SelectBoxOption didn't seem to > have a toString function - and then why trying to access what should be the > value and name the same way as with other objects derived at some level from > Tag blew up instead of working happily. > > 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 .. and hopefully you're using version control :D -nathan
Re: [PHP] String passed to object constructor turning into an instance of that object?
Nathan Nobbe wrote: probly something screwy going on w/ the old style of naming constructors. 2 things, 1. can you post the Tag constructor as it reads now? function Tag($tag='', $tagContent='') { $this->tagContent = $tagContent; $this->tag = $tag; $this->showEndTag = false; $this->attributes = array(); $this->children = array(); } 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. :( Copying the old constructor back in resolved that, but I'm not sure whether that reintroduces the root problem. Other objects derived from Tag seem to work just fine; I came into this chunk of the code trying to find out why a SelectBoxOption didn't seem to have a toString function - and then why trying to access what should be the value and name the same way as with other objects derived at some level from Tag blew up instead of working happily. 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. (A "don't-break-crusty-old-code" option for php.ini would be handy...) The class hierarchy I've dug up so far looks like this (and appears to have been entirely defined by the original developer): Object Fieldset RadioButtonGroup Tag Column FormObject FormInput CheckBox DateSelector Editor FileField FormButton HiddenField PasswordField RadioButton SelectBox PopulatedSelectBox RecursiveSelectBox TextArea TextField Form Row Table SelectBoxOption -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into an instance of that object?
On Thu, Dec 16, 2010 at 2:29 PM, Kris Deugau 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!\n"; } >>> // else { print " name $name\n"; } >>> if ($value == "") { echo " missing value!\n"; } >>> } >>> >>> >>> will parse and execute, but: >>> - the page will contain "missing value!" for each in the >>> this is generating >>> - it will *not* contain "missing name!" >>> - the tags in the final output don't have content or value >>> (they should have both). >>> >>> If I uncomment that else, I get: >>> >>> >>> adding option with >>> name >>> >>> Catchable fatal error: Object of class SelectBoxOption could not be >>> converted to string in >>> /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
Re: [PHP] String passed to object constructor turning into an instance of that object?
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!\n"; } // else { print " name $name\n"; } if ($value == "") { echo " missing value!\n"; } } will parse and execute, but: - the page will contain "missing value!" for each in the this is generating - it will *not* contain "missing name!" - the tags in the final output don't have content or value (they should have both). If I uncomment that else, I get: adding option with name Catchable fatal error: Object of class SelectBoxOption could not be converted to string in /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
RE: [PHP] String passed to object constructor turning into an instance of that object?
> -Original Message- > From: Kris Deugau [mailto:kdeu...@vianet.ca] > Sent: Thursday, December 16, 2010 11:57 AM > To: php-general@lists.php.net > Subject: [PHP] String passed to object constructor turning into an instance of > that object? > > I'm in the process of migrating customer websites off an old legacy server > that's pushing EOL, and starting to show hardware failures. > > One site is throwing errors on what, so far as I can tell, should be perfectly > working code. > > The original code works fine on both CentOS 3 (PHP 4.3.2) and CentOS 4 > (4.3.9); the "new" server is still a bit outdated (Debian etch plus some > backports and updates from lenny; PHP 5.2.0). > > The site was designed by staff at a previous hosting company and uses a > combination of the Fusebox app framework (which seems to work OK, after > a few relatively minor fixes) and a custom OOP structure. > > I'm not really sure what the actual problem is, but I've reached the point > where this: > > >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!\n"; } > // else { print " name $name\n"; } > if ($value == "") { echo " missing value!\n"; } > } > > > will parse and execute, but: > - the page will contain "missing value!" for each in the > this is generating > - it will *not* contain "missing name!" > - the tags in the final output don't have content or value > (they should have both). > > If I uncomment that else, I get: > > > adding option with > name > > Catchable fatal error: Object of class SelectBoxOption could not be > converted to string in > /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. Regards, Tommy > > I found the place this object is created, and added some debugging > output before *and* after that call: > > > echo "adding option ".$row->$nameField." with ". >$row->$valueField."\n"; > $this->add(new SelectBoxOption($row->$nameField, > $row->$valueField, $selected)); > echo "added option ".$row->$nameField." with ". >$row->$valueField."\n"; > > > which behaves correctly and spits out the name and value (retrieved from > a database - thankfully I haven't had to track *that* down... yet). > > Can anyone explain why a string passed by value (apparently) would > suddenly mutate into a SelectBoxOption object? I've confirmed that this > is exactly what happens by adding this: > > > if (is_a($name,'SelectBoxOption')) { >print "name isn't a SelectBoxOption, silly rabbit!\n"; > } > > > as the very next set of lines after "function SelectBoxOption(". > > I wondered while typing this if $name and $value might have ended up as > special variables somewhere, but renaming them with an opt_ prefix > didn't change anything. > > -kgd > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php