note 102307 modified in language.references.spot by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.