Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #40509 : key() function changed behaviour if global array is used within function
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 11th July 05:27
php-bugs
External User
 
Posts: 1
Default #40509 : key() function changed behaviour if global array is used within function



From: alex dot killing at gmx dot de
Operating system: MaxOsX/RedHat
PHP version: 5.2.1
PHP Bug Type: Arrays related
Bug description: key() function changed behaviour if global array is used within function

Description:
------------
If a global array is assigned to a local variable as in the example, and
the local variable is iterated afterwards, the key() function changed the
behaviour in the global scope with PHP 5.2.1.

Reproduce code:
---------------
<?php

function foo()
{
global $arr;

$c = $arr["v"];
foreach ($c as $v) {}
}

$arr["v"] = array("a");

echo "-".key($arr["v"])."-"; // prints "0"
foo();
echo "<br/>-".key($arr["v"])."-"; // prints "" since 5.2.1 ("0" on all
prior versions)


?>

Expected result:
----------------
-0-
-0-

Actual result:
--------------
-0-
--

--
Edit bug report at http://bugs.php.net/?id=40509&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40509&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40509&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40509&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40509&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=40509&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40509&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40509&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40509&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40509&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40509&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=40509&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=40509&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40509&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40509&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40509&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40509&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40509&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40509&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40509&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40509&r=mysqlcfg
  Reply With Quote


  sponsored links


2 11th July 08:28
External User
 
Posts: 1
Default #40509 : key() function changed behaviour if global array is used within function



ID: 40509
Updated by: tony2001@php.net
Reported By: alex dot killing at gmx dot de
-Status: Open
+Status: Assigned
Bug Type: Arrays related
Operating System: MaxOsX/RedHat
PHP Version: 5.2.1
-Assigned To:
+Assigned To: dmitry


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

[2007-02-16 15:24:36] alex dot killing at gmx dot de

Description:
------------
If a global array is assigned to a local variable as in the example,
and the local variable is iterated afterwards, the key() function
changed the behaviour in the global scope with PHP 5.2.1.

Reproduce code:
---------------
<?php

function foo()
{
global $arr;

$c = $arr["v"];
foreach ($c as $v) {}
}

$arr["v"] = array("a");

echo "-".key($arr["v"])."-"; // prints "0"
foo();
echo "<br/>-".key($arr["v"])."-"; // prints "" since 5.2.1 ("0" on all
prior versions)


?>

Expected result:
----------------
-0-
-0-

Actual result:
--------------
-0-
--


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=40509&edit=1
  Reply With Quote
3 13th July 00:24
External User
 
Posts: 1
Default #40509 : key() function changed behaviour if global array is used within function


ID: 40509
Updated by: dmitry@php.net
Reported By: alex dot killing at gmx dot de
Status: Assigned
Bug Type: Arrays related
Operating System: MaxOsX/RedHat
PHP Version: 5.2.1
Assigned To: dmitry
New Comment:

see also http://bugs.php.net/bug.php?id=40705


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

[2007-02-16 15:24:36] alex dot killing at gmx dot de

Description:
------------
If a global array is assigned to a local variable as in the example,
and the local variable is iterated afterwards, the key() function
changed the behaviour in the global scope with PHP 5.2.1.

Reproduce code:
---------------
<?php

function foo()
{
global $arr;

$c = $arr["v"];
foreach ($c as $v) {}
}

$arr["v"] = array("a");

echo "-".key($arr["v"])."-"; // prints "0"
foo();
echo "<br/>-".key($arr["v"])."-"; // prints "" since 5.2.1 ("0" on all
prior versions)


?>

Expected result:
----------------
-0-
-0-

Actual result:
--------------
-0-
--


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=40509&edit=1
  Reply With Quote
4 14th July 15:17
External User
 
Posts: 1
Default #40509 : key() function changed behaviour if global array is used within function


ID: 40509
Updated by: ashnazg@php.net
Reported By: alex dot killing at gmx dot de
Status: Assigned
Bug Type: Arrays related
Operating System: MaxOsX/RedHat
PHP Version: 5.2.1
Assigned To: dmitry
New Comment:

Tested this example against the 5.2.1 zipfile from php.net on WinXP and
the problem does occur.

Also tested it against the 5.2 snapshot (php5.2-win32-200703191630.zip)
from php.net, on WinXP, and the problem seems to still exist.


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

[2007-03-06 13:19:33] dmitry@php.net

see also http://bugs.php.net/bug.php?id=40705

------------------------------------------------------------------------

[2007-02-16 15:24:36] alex dot killing at gmx dot de

Description:
------------
If a global array is assigned to a local variable as in the example,
and the local variable is iterated afterwards, the key() function
changed the behaviour in the global scope with PHP 5.2.1.

Reproduce code:
---------------
<?php

function foo()
{
global $arr;

$c = $arr["v"];
foreach ($c as $v) {}
}

$arr["v"] = array("a");

echo "-".key($arr["v"])."-"; // prints "0"
foo();
echo "<br/>-".key($arr["v"])."-"; // prints "" since 5.2.1 ("0" on all
prior versions)


?>

Expected result:
----------------
-0-
-0-

Actual result:
--------------
-0-
--


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=40509&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666