ID:               42932
 User updated by:  cpu-g at yahoo dot com dot tw
 Reported By:      cpu-g at yahoo dot com dot tw
 Status:           Open
-Bug Type:         Apache2 related
+Bug Type:         Performance problem
 Operating System: win xp
 PHP Version:      5.2.4
 New Comment:

I corrected the Category.


Previous Comments:
------------------------------------------------------------------------

[2007-10-11 17:42:58] cpu-g at yahoo dot com dot tw

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 this bug report at http://bugs.php.net/?id=42932&edit=1

Reply via email to