Re: question about using $this as a method in a function argument

From: Date: Sat, 21 Jan 2006 22:23:28 +0000
Subject: Re: question about using $this as a method in a function argument
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-229012@lists.php.net to get a copy of this message
I have a question about using $this as an argument in a method.
As I understand it, the only issue here is if you are passing $this from constructor of your class from PHP 4. In short, when you do $var = new MyClass(); you are actually storing a copy of what constructor was seeing as $this, and if you passed $this from constructor to an outside function that stores it somewhere, then you now have two different objects. Way to circumvent this is to use $var = & new MyClass(); ie, use a reference, or make sure that your script will be running on PHP5. If you do the above thing with reference in PHP 5 though, you will get a warning that this is deprecated. Hope this helps... Boban. -- Open source PHP code generator for DB operations http://sourceforge.net/projects/bfrcg/

« previous php.general (#229012) next »