#46458 [NEW]: Tricky, undocumented trait of global keyword
| From: | gmtfn at yahoo dot com | Date: | Sat, 01 Nov 2008 19:24:35 +0000 |
| Subject: | #46458 [NEW]: Tricky, undocumented trait of global keyword | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-1288@lists.php.net to get a copy of this message | ||
From: gmtfn at yahoo dot com
Operating system: Linux
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: Tricky, undocumented trait of global keyword
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 bug report at http://bugs.php.net/?id=46458&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46458&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46458&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46458&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46458&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46458&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46458&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46458&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46458&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46458&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46458&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46458&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46458&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46458&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46458&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46458&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46458&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46458&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46458&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46458&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46458&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46458&r=mysqlcfg