PHP5 objects are passed by reference -- for dummies
<?php | |
function change_array( $array ) { | |
$array[ 'x' ] = 2; | |
} | |
$bar = array(); | |
$bar['x'] = 1; | |
change_array( $bar ); | |
var_dump( $bar['x'] ); // 1 -- as expected | |
function change_object( $object ) { | |
$object->x = 2; | |
} | |
$foo = new stdClass; | |
$foo->x = 1; | |
change_object( $foo ); | |
var_dump( $foo->x ); // 2, because, PHP5 objects passed by reference, bitches ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thanks @rmccue -- https://twitter.com/ozh/statuses/415899450809122816