From: cpu-g at yahoo dot com dot tw
Operating system: win xp
PHP version: 5.2.4
PHP Bug Type: Apache2 related
Bug description: reference operator is different between $GLOBALS array and
declared global
Description:
------------
I use reference operator in local variable calculatedly. Because I
know that reference is similar to pointer in C language and they
are dangerous in some situation,I want to know that if PHP allow
reference to local variable.
But $GLOBALS array allowed reference to local variable,
declared global keyword failed.
Reproduce code:
---------------
<?php
$global1=100;
$global2=100;
function foo()
{
$local=10;
global $global1;
$global1=&$local;
$GLOBALS["global2"] =&$local;
}
foo();
echo "$global1 : $global2 <BR>";
?>
Expected result:
----------------
100 : 100 or 10 : 10.
1st output is good for any situation. It guarantee that reference to the
local variable is not allowed. So Reference operator can't work in 2 style:
$GLOBALS array and declared global. but actually
only $GLOBALS array can work.
2st output is bad. It symbolize that we still can access local
variable in function foo() after calling foo(). It may result in
access violation.
Actual result:
--------------
100 : 10
--
Edit bug report at http://bugs.php.net/?id=42932&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42932&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42932&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42932&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42932&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42932&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42932&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42932&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42932&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42932&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42932&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42932&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42932&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42932&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42932&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42932&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42932&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42932&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42932&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42932&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42932&r=mysqlcfg