From:             webmaster at korfballworld dot com
Operating system: MacOS X, Linux
PHP version:      4.3.10
PHP Bug Type:     Arrays related
Bug description:  Using array_multisort on a copy of an array affects the 
original

Description:
------------
I have a class function that uses an internal array. 
When making a copy of this array and performing 
array_multisort on the copy of the array, using the 
original array lateron in the class results in an array, 
hinting the original array has been affected, UNLESS I 
give a statement involving the original array.

See the code sample.

Adding a line where the key of one element of the 
original array is printed before the array_multisort is 
called results in the original array keeping its 
original keys, where otherwise the key are reordered as 
if the original array was used in the array_multisort. 
This was testes by printing a key only after calling the 
array_multisort as well as both before and after.

(It seems to be similar to an old bug #8130 which was 
closed, but I feel this to be such a fundemental error 
that I post this one anyway. To me this messes up 
'sensible' programming. I couldn't explain this to any 
serious programmer. It's like working on a reference to 
a variable instead of the new variable it's supposed to 
be.)

Reproduce code:
---------------
$teams_list = $this->_teams;
# This line is to fix a weird bug regarding the array_multisort screwing
up the original array, despite using the copy $teams_list otherwise
print "<!-- ".key($this->_teams)." -->";
array_multisort($teams, SORT_ASC, SORT_STRING, $teams_list);

Full class copied for viewing on:
http://korfball.kicks-ass.org/assets/classes/League.inc.php.txt

Page using the class:
http://korfball.kicks-ass.org/leagues/00072/
I can 'turn on' the error when needed

Expected result:
----------------
I expect to have only the array $teams_list to be 
affected by the array_multisort, so using the original 
$this->_teams later in the class will still work the 
same.

Actual result:
--------------
Removing the print line with key($this->_teams) will 
result in an 'Fatal error: Call to a member function on 
a non-object' later in the class where $this->_teams is 
used.

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

Reply via email to