php - $GLOBALS superglobal gets modified when passed to a function -


i came across weird behavior in php:

function f($var) { // not using references     foreach ($var $k => $v) {         unset($var[$k]); // shouldn't unset copy?!     } }  print '<pre>'; var_dump($globals); // array f($globals); var_dump($globals); // null?! 

http://3v4l.org/dqmqn

anybody know why happening?

print out it’s deleting , enable warnings see what’s happening! =)

$globals contains globals. unset it, removes actual global variable. if just pass-by-reference behaviour, empty array, not null.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -