PHP 4.0 Bug #3082: passing by reference between globals fails outside of function
| From: | jmeskill at libertydistribution dot com | Date: | Sun, 02 Jan 2000 21:03:44 +0000 |
| Subject: | PHP 4.0 Bug #3082: passing by reference between globals fails outside of function | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-14207@lists.php.net to get a copy of this message | ||
From: jmeskill@libertydistribution.com
Operating system: RedHat 6.1
PHP version: 4.0 Latest CVS (02/01/2000)
PHP Bug Type: Scripting Engine problem
Bug description: passing by reference between globals fails outside of function
I am trying to pass by reference from a global variable to another global variable inside of a
function. From what I can tell it does not work... however, if I try it outside of a function it
works just fine. Is this by design? Or am I doing something wrong? Here is an example of what
works and what doesn't.
<doesnotwork>
<?php
function test()
{
global $current;
global $parent;
if (!is_array($current)) {
print("** inside if **<br>");
$parent[0] = array();
$current = &$parent[0];
} else {
print("** inside else **<br>");
$current[0] = array();
$current = &$current[0];
}
}
for ($i = 0; $i < 2; $i++) {
test();
}
$current[0] = "me";
print("Current[0]=".$current[0]."<br>");
print("Parent[0][0][0]=".$parent[0][0][0]."<br>");
?>
result is
** inside if **
** inside if **
Current[0]=me
Parent[0][0][0]=
</doesnotwork>
<doeswork>
<?php
for ($i=0; $i < 2; $i++) {
if (!is_array($current)) {
print("** inside if **<br>");
$parent[0] = array();
$current = &$parent[0];
} else {
$current[0] = array();
$current = &$current[0];
}
}
$current[0] = "me";
print("Current[0]=".$current[0]."<br>");
print("Parent[0][0][0]=".$parent[0][0][0]."<br>");
?>
** inside if **
** inside else **
Current[0]=me
Parent[0][0][0]=me
</doeswork>