Skip to content

Instantly share code, notes, and snippets.

@ozh ozh/gist:8125334
Created Dec 25, 2013

Embed
What would you like to do?
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 !
@ozh

This comment has been minimized.

Copy link
Owner Author

commented Dec 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.