php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30587 Array assignment with array_multisort
Submitted: 2004-10-27 20:09 UTC Modified: 2005-02-01 19:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ian_mclaughlin at blueyonder dot co dot uk Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.3.9 OS: Win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ian_mclaughlin at blueyonder dot co dot uk
New email:
PHP Version: OS:

 

 [2004-10-27 20:09 UTC] ian_mclaughlin at blueyonder dot co dot uk
Description:
------------
this code gives the impression that array assignment is actually done by pointer sharing, when it should be done by copying.

Reproduce code:
---------------
<?php
//
$master_A=array(1,2,4,3);
$master_B=array(1,3,2,4);
$A = $master_A;
$B = $master_B;
	echo"<br/>BEFORE MULTISORT";
	echo"<br/>master_A<br/>";
	print_r($master_A);
	echo"<br/>master_B<br/>";
	print_r($master_B);
array_multisort($A, $B); 
	echo"<br/>AFTER MULTISORT";
	echo"<br/>master_A<br/>";
	print_r($master_A);
	echo"<br/>master_B<br/>";
	print_r($master_B);
?>

Expected result:
----------------
BEFORE MULTISORT
master_A
Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 3 )
master_B
Array ( [0] => 1 [1] => 3 [2] => 2 [3] => 4 )
AFTER MULTISORT
master_A
Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 3 )
master_B
Array ( [0] => 1 [1] => 3 [2] => 2 [3] => 4 )


Actual result:
--------------
BEFORE MULTISORT
master_A
Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 3 )
master_B
Array ( [0] => 1 [1] => 3 [2] => 2 [3] => 4 )
AFTER MULTISORT
master_A
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
master_B
Array ( [0] => 1 [1] => 3 [2] => 4 [3] => 2 )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-16 11:44 UTC] ian_mclaughlin at blueyonder dot co dot uk
Thanks for your response. 

Variables (master_A and master_B) change even though I have performed no operation on them since assignment. All the documentation I can find does not support this behaviour. If this actually is the expected behaviour, please explain why.
 [2004-11-19 17:57 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Yes, I was wrong, sorry.
This is fixed by now.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 30 12:01:31 2025 UTC