note 103660 added to language.references.spot
| From: | AbimaelRodrguezColn at osu1 dot php dot net | Date: | Tue, 26 Apr 2011 18:55:44 +0000 |
| Subject: | note 103660 added to language.references.spot | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179176@lists.php.net to get a copy of this message | ||
This is one way to check if is a reference
<?php
$a = 1;
$b =& $a;
$c = 2;
$d = 3;
$e = array($a);
function is_reference($var){
$val = $GLOBALS[$var];
$tmpArray = array();
/**
* Add keys/values without reference
*/
foreach($GLOBALS as $k => $v){
if(!is_array($v)){
$tmpArray[$k] = $v;
}
}
/**
* Change value of rest variables
*/
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());
}
}
$bool = $val != $GLOBALS[$var];
/**
* Restore defaults values
*/
foreach($tmpArray as $k => $v){
$GLOBALS[$k] = $v;
}
return $bool;
}
var_dump(is_reference('a'));
var_dump(is_reference('b'));
var_dump(is_reference('c'));
var_dump(is_reference('d'));
?>
This won't check if reference is inside a array.
----
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/103660
Del: integrated -- https://master.php.net/note/delete/103660/integrated
Del: useless -- https://master.php.net/note/delete/103660/useless
Del: bad code -- https://master.php.net/note/delete/103660/bad+code
Del: spam -- https://master.php.net/note/delete/103660/spam
Del: non-english -- https://master.php.net/note/delete/103660/non-english
Del: in docs -- https://master.php.net/note/delete/103660/in+docs
Del: other reasons-- https://master.php.net/note/delete/103660
Reject -- https://master.php.net/note/reject/103660
Search -- https://master.php.net/manage/user-notes.php