You are here: Re: PHP 4 OOP problem « PHP Programming Language « IT news, forums, messages
Re: PHP 4 OOP problem

Posted by Nicholas Sherlock on 02/03/06 01:51

Nicholas Sherlock wrote:
> This malfunctions in a weird way in PHP 4 (I get a truncated tree). In
> desperation, I downloaded the trial of PHPEdit to use the debugger, and
> the program worked flawlessly! I suspect that the difference is that
> PHPEdit uses PHP 5 while my testing server and my production server are
> using PHP 4 (Both were operating on the exact same data).

I finally tracked it down to the stupid way that PHP 4 makes a copy of
an object unless you explicitly pass it by reference with the '&'
character. I thought that I had it covered, I sprinkled & everywhere it
would go when I worked with my tree. I eventually tracked the problem
down to the code I used for adding a child to the list of child nodes:

function builddown(&$childnode)
{
array_push($this->children,$childnode);
}

This results in a copy of $childnode being pushed on to the array, not a
reference to $childnode. Array_push doesn't take a reference for the
object being pushed. Solution:

array_push($this->children,null);
$this->children[count($this->children)-1]=&$childnode;

(There is probably a neater way of doing that)

If you want OOP, don't use PHP 4. I wish I had the choice.

Cheers,
Nicholas Sherlock

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация