note 86742 added to language.variables.scope

From: Date: Sat, 01 Nov 2008 20:46:50 +0000
Subject: note 86742 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-146022@lists.php.net to get a copy of this message
Qualifying a variable with the keyword global has a tricky but undocumented effect -- it doesn't merely allow code in a function to access global variable, but it actually creates global variables. This should have been clearly described in the manual. Reproduce code: --------------- function main() { global $num; $num = 10; test(); } function test() { $number = $GLOBALS['num']; echo "num = $number"; } I expected this result: num = because $num isn't declared outside all functions but got this: num = 10 ---- Server IP: 64.71.164.2 Probable Submitter: 98.201.56.252 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/86742 Del: integrated -- https://master.php.net/note/delete/86742/integrated Del: useless -- https://master.php.net/note/delete/86742/useless Del: bad code -- https://master.php.net/note/delete/86742/bad+code Del: spam -- https://master.php.net/note/delete/86742/spam Del: non-english -- https://master.php.net/note/delete/86742/non-english Del: in docs -- https://master.php.net/note/delete/86742/in+docs Del: other reasons-- https://master.php.net/note/delete/86742 Reject -- https://master.php.net/note/reject/86742 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146022) next »