Re: question about objects and references

From: Date: Mon, 13 May 2002 14:33:48 +0000
Subject: Re: question about objects and references
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-97355@lists.php.net to get a copy of this message
"Sascha Mantscheff" <smantscheff@qualimedic.de> schrieb im Newsbeitrag news:02051311162204.02523@pico... > When I pass an object as a parameter to a function as "$this", this is an > object reference (according to the docs). it depends on the function. if you call it by value, not by reference, then the function will contain a copy of the original not a pointer. Doesn't matter if you call the function with $this or some other reference. $this is a self-reference to the object. you can only use it inside the object itself. but as soon as you send it to a function as "by value"-parameter, a copy of the object will be used inside the function. if you call the function "by reference" you'll hold a pointer inside the function > I store this reference in a local variable called $someObject. $someObject > now contains an object pointer. Ok, let's say the parameter is send to the functions "by reference". Then you are right, it'll point to the original object, but: function (&$objRef) { $blah = $objRef; } -> $blah will hold a copy! function (&$objRef) { $blah = &$objRef; } -> $blah will hold a reference! > I pass $someObject to another function. Is this a reference to the original > $this, or is it a copy of the object? Read what i wrote above and answer it yourself. Regards Michael. > All function calls are by value, not by reference (without the "&" name > modifier). > > > s.m.

« previous php.general (#97355) next »