One may check reference to any object by simple operator==(
object). Example:
class A {}
$oA1 = new A();
$roA = & $oA1;
echo "roA and oA1 are " . ( $roA == $oA1 ?
"same" : "not same") .
"<br>";
$oA2 = new A();
$roA = & $roA2;
echo "roA and oA1 are " . ( $roA == $oA1 ?
"same" : "not same") .
"<br>";
Output:
roA and oA1 are same
roA and oA1 are not same
Current technique might be useful for caching in objects
when inheritance is used and only base part of extended
class should be copied (analog of C++: oB = oA):
class A {
/* Any function changing state of A should set $bChanged
to true */
public function isChanged() { return $this->bChanged; }
private $bChanged;
//...
}
class B extends A {
// ...
public function set( &$roObj) {
if( $roObj instanceof A) {
if( $this->roAObj == $roObj &&
$roObj->isChanged()) {
/* Object was not changed do not need to copy A part
of B */
} else {
/* Copy A part of B */
$this->roAObj = &$roObj;
}
}
}
private $roAObj;
}
----
Server IP: 64.246.30.37
Probable Submitter: 131.225.163.89
----
Manual Page -- http://www.php.net/manual/en/language.references.spot.p
hp
Edit -- http://master.php.net/manage/user-notes.php?action=
edit+61744
Delete: added to the manual -- htt
p://master.php.net/manage/user-notes.php?action=delete+61744
&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.
php.net/manage/user-notes.php?action=delete+61744&report
=yes&reason=bad+code
Delete: spam -- http://master.php.
net/manage/user-notes.php?action=delete+61744&report=yes
&reason=spam
Delete: useless -- http://master.p
hp.net/manage/user-notes.php?action=delete+61744&report=
yes&reason=useless
Delete: non-english -- http://mast
er.php.net/manage/user-notes.php?action=delete+61744&rep
ort=yes&reason=non-english
Delete: already in docs -- http://
master.php.net/manage/user-notes.php?action=delete+61744&
;report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-
notes.php?action=delete+61744&report=yes
Reject -- http://master.php.net/manage/user-
notes.php?action=reject+61744&report=yes
Search -- http://ma
ster.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|