note 119715 deleted from functions.arguments by salathe

From: Date: Tue, 09 Aug 2016 13:44:10 +0000
Subject: note 119715 deleted from functions.arguments by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206249@lists.php.net to get a copy of this message
Note Submitter: gabriel at figdice dot org ---- The manual says that passing arguments by value is the default. This can lead to confusion if the argument is an object: <?php $x = new stdClass(); $x->y = 1; function foo( $o ) // Notice the absence of & in front of the arg { $o->y = 2; } foo($x); var_dump($x); ?> the var dump shows that $x->y is 2, so the passed object, despite the absence of a & in the function signature, gets modified by the function. This is different with arrays, which are copied-on-write if you modify their contents, and there was no & in front of the argument in the function signature.

« previous php.notes (#206249) next »