note 74620 added to language.variables.predefined

From: Date: Fri, 20 Apr 2007 14:15:34 +0000
Subject: note 74620 added to language.variables.predefined
Groups: php.notes 
Request: Send a blank email to php-notes+get-125627@lists.php.net to get a copy of this message
Dealing with "superglobals" and functions is not as straightforward as it may seem when you're doing plenty manipulations. For example: <?php function some_other_method() { echo $_REQUEST['id']; } function some_method() { $_REQUEST['id'] = 440; some_other_method(); } ?> Calling some_method() will cause a warning-level error by PHP informing you that "id" is not set in some_other_method(). However, if you instead use: <?php $_REQUEST['id'] = 0; function some_other_method() { echo $_REQUEST['id']; } function some_method() { $_REQUEST['id'] = 440; some_other_method(); } ?> Then the script will echo 440. In consequence, if you manually attempt to add keys to the superglobals, those keys *aren't* automatically superglobal. The above example isn't very sensible, of course, but this can be a huge gotcha if you're juggling user data between functions and you're unwittingly being forced to work inside a function (e.g. via PHP include in TYPO3). Unfortunately, global $_REQUEST['id'] won't save you, either - it causes a parse error - nor will a global $_REQUEST change anything after you've set the keys... consequently making it hard to conviniently 'hack' outdated scripts by making them believe they're still running in a different environment. The only "solution" to this issue is to use parameters. ---- Server IP: 217.13.201.10 Probable Submitter: 84.46.119.45 ---- Manual Page -- http://www.php.net/manual/en/language.variables.predefined.php Edit -- https://master.php.net/note/edit/74620 Del: integrated -- https://master.php.net/note/delete/74620/integrated Del: useless -- https://master.php.net/note/delete/74620/useless Del: bad code -- https://master.php.net/note/delete/74620/bad+code Del: spam -- https://master.php.net/note/delete/74620/spam Del: non-english -- https://master.php.net/note/delete/74620/non-english Del: in docs -- https://master.php.net/note/delete/74620/in+docs Del: other reasons-- https://master.php.net/note/delete/74620 Reject -- https://master.php.net/note/reject/74620 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125627) next »