here's an example of what i said:
<?php
class obj {
Var $a = 1;
function byVal() {
byVal($this);
}
function byRef() {
byRef($this);
}
}
function byVal($obj) {
echo $obj->a += 1;
}
function byRef(&$obj) {
echo $obj->a += 1;
}
///////////////////////////////////////////
$a = &new obj();
$a->byVal();
echo "<br>";
echo $a->a;
echo "<br>";
$a->byRef();
echo "<br>";
echo $a->a;
?>
Regards Michael
"Michael Virnstein" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> "Sascha Mantscheff" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> 02051311162204.02523@pico">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.
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php