note 103658 added to language.references.spot
| From: | abimaelrc at gmail dot com | Date: | Tue, 26 Apr 2011 18:30:55 +0000 |
| Subject: | note 103658 added to language.references.spot | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179172@lists.php.net to get a copy of this message | ||
One way to check if is a reference
<?php
$a = 1;
$b =& $a;
$c = 2;
$d = 3;
function is_reference($var){
$val = $GLOBALS[$var];
foreach($GLOBALS as $k => $v){
if($k != 'GLOBALS'
&& $k != '_POST'
&& $k != '_GET'
&& $k != '_COOKIE'
&& $k != '_FILES'
&& $k != $var
&& !is_array($v)
){
usleep(1);
$GLOBALS[$k] = md5(microtime());
}
}
return $val != $GLOBALS[$var];
}
var_dump(is_reference('a')); // bool(true)
var_dump(is_reference('b')); // bool(true)
var_dump(is_reference('c')); // bool(false)
var_dump(is_reference('d')); // bool(false)
?>
This wont check reference inside arrays.
----
Server IP: 69.147.83.197
Probable Submitter: 64.237.141.222
----
Manual Page -- http://www.php.net/manual/en/language.references.spot.php
Edit -- https://master.php.net/note/edit/103658
Del: integrated -- https://master.php.net/note/delete/103658/integrated
Del: useless -- https://master.php.net/note/delete/103658/useless
Del: bad code -- https://master.php.net/note/delete/103658/bad+code
Del: spam -- https://master.php.net/note/delete/103658/spam
Del: non-english -- https://master.php.net/note/delete/103658/non-english
Del: in docs -- https://master.php.net/note/delete/103658/in+docs
Del: other reasons-- https://master.php.net/note/delete/103658
Reject -- https://master.php.net/note/reject/103658
Search -- https://master.php.net/manage/user-notes.php