Created
September 6, 2011 16:12
-
-
Save meglio/1198014 to your computer and use it in GitHub Desktop.
Unexpected behavior of arrays with referenced elements, in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array(1, 5); | |
$a =& $arr[0]; //$a and $arr[0] are in the same reference set | |
$arr2 = $arr; //not an assignment-by-reference! | |
$arr2[0]++; | |
$arr2[1]++; | |
var_dump($a); | |
var_dump($arr); | |
// Result is unexpected: | |
// int(2) array(2) { [0]=> &int(2) [1]=> int(5) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment