#32031 [Bgs]: Using array_multisort on a copy of an array affects the original
| From: | webmaster at korfballworld dot com | Date: | Mon, 21 Feb 2005 17:48:08 +0000 |
| Subject: | #32031 [Bgs]: Using array_multisort on a copy of an array affects the original | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74337@lists.php.net to get a copy of this message | ||
ID: 32031
User updated by: webmaster at korfballworld dot com
Reported By: webmaster at korfballworld dot com
Status: Bogus
Bug Type: Arrays related
Operating System: MacOS X, Linux
PHP Version: 4.3.10
New Comment:
Sorry, but the bug # you mention clearly does NOT relate
to my problem!!! The array_multisort DOES work, it just
affects the original array of the copy used in the
array_multisort!!! Please read carefully before calling
my entry 'Bogus'!! :-(
As I wrote before it seems to be similar to the very old
bug # 8130!
Previous Comments:
------------------------------------------------------------------------
[2005-02-21 18:38:20] tony2001@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same.
Thank you for your interest in PHP.
See #25359.
------------------------------------------------------------------------
[2005-02-20 04:26:53] webmaster at korfballworld dot com
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 this bug report at http://bugs.php.net/?id=32031&edit=1