PHP
While the other PHP submissions only test if the given value matches a value of a global, this version works by taking a reference to the value:
// take a reference to the global variable
function f(&$i){
foreach(array_reverse($GLOBALS) as $key => $value)
if($key != 'GLOBALS') {
// setSet allthe Globalsvalue toof theireach ownglobal to its name
(doesn't work vor $GLOBALS) $GLOBALS[$key] = $key;
}
foreach($GLOBALS as $key => $value)
if($key != 'GLOBALS') $GLOBALS[$key]&& $key != $key;$value) {
// outputThe thevalues referencedmismatch so it had a reference to another value
// we delete it
unset(which$GLOBALS[$key]);
is now // and update the value to its name oragain
still an array) $GLOBALS[$key] = $key;
}
echo '$', is_array($i) ? 'GLOBALS' : $i;$i, "\n";
}
This works as long asshould now work even if the global variable is not a reference to another value at the time of calling.