note 102307 modified in language.references.spot by danbrown
| From: | danbrown@php.net | Date: | Tue, 08 Feb 2011 12:25:15 +0000 |
| Subject: | note 102307 modified in language.references.spot by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176766@lists.php.net to get a copy of this message | ||
Here is a simple function which checks for reference, and works with objects by the test I did. Have
now fully checked under PHP version 5.2+ and can confirm that it works for everything I could think
of, including objects.
<?php
function is_reference_to(&$a, &$b)
{
if ($a !== $b)
return false; //Important.
$temp = $a;
$a = ($a === null) ? "" : null;
$res = ($b === $a);
$a = $temp;
return $res;
}
?>
--was--
This version of the function is much more compact but works the same way. Have now fully checked
under PHP version 5.2+ and can confirm that it works for everything I could think of, including
objects.
<?php
function is_reference_to(&$a, &$b)
{
if ($a !== $b)
return false; //Important.
$temp = $a;
$a = ($a === null) ? "" : null;
$res = ($b === $a);
$a = $temp;
return $res;
}
?>
http://php.net/manual/en/language.references.spot.php