#46458 [Opn->Bgs]: Tricky, undocumented trait of global keyword

From: Date: Tue, 04 Nov 2008 16:32:26 +0000
Subject: #46458 [Opn->Bgs]: Tricky, undocumented trait of global keyword
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1314@lists.php.net to get a copy of this message
ID: 46458 Updated by: vrana@php.net Reported By: gmtfn at yahoo dot com -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Linux PHP Version: Irrelevant New Comment: Variables in PHP aren't declared so storing a value to a variable creates it. Previous Comments: ------------------------------------------------------------------------ [2008-11-01 19:24:34] gmtfn at yahoo dot com Description: ------------ 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 be clearly described in the manual. Reproduce code: --------------- function main() { global $num; $num = 10; test(); } function test() { $number = $GLOBALS['num']; echo "num = $number"; } Expected result: ---------------- num = because $num isn't declared outside all functions Actual result: -------------- num = 10 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46458&edit=1

« previous php.doc.bugs (#1314) next »