note 55689 added to language.references.spot
| From: | SergioSantana:ssantana at tlaloc dot imta dot mx | Date: | Wed, 10 Aug 2005 16:30:28 +0000 |
| Subject: | note 55689 added to language.references.spot | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93383@lists.php.net to get a copy of this message | ||
Sometimes an object's method returning a reference to itself is required. Here is a way to code
it:
<?php
class MyClass {
public $datum;
public $other;
function &MyRef($d) { // the method
$this->datum = $d;
return $this; // returns the reference
}
}
$a = new MyClass;
$b = $a->MyRef(25); // creates the reference
echo "This is object \$a: \n";
print_r($a);
echo "This is object \$b: \n";
print_r($b);
$b->other = 50;
echo "This is object \$a, modified" .
" indirectly by modifying ref \$b: \n";
print_r($a);
?>
This code outputs:
This is object $a:
MyClass Object
(
[datum] => 25
[other] =>
)
This is object $b:
MyClass Object
(
[datum] => 25
[other] =>
)
This is object $a, modified indirectly by modifying ref $b:
MyClass Object
(
[datum] => 25
[other] => 50
)
----
Manual Page -- http://www.php.net/manual/en/language.references.spot.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55689
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55689&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55689&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55689&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55689&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55689&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55689&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55689&report=yes
Search -- http://master.php.net/manage/user-notes.php