note 119715 added to functions.arguments

From: Date: Tue, 09 Aug 2016 12:03:08 +0000
Subject: note 119715 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-206248@lists.php.net to get a copy of this message
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. ---- Server IP: 83.137.20.135 Probable Submitter: 176.106.229.25 ---- Manual Page -- http://php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/119715 Del: integrated -- https://master.php.net/note/delete/119715/integrated Del: useless -- https://master.php.net/note/delete/119715/useless Del: bad code -- https://master.php.net/note/delete/119715/bad+code Del: spam -- https://master.php.net/note/delete/119715/spam Del: non-english -- https://master.php.net/note/delete/119715/non-english Del: in docs -- https://master.php.net/note/delete/119715/in+docs Del: other reasons-- https://master.php.net/note/delete/119715 Reject -- https://master.php.net/note/reject/119715 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206248) next »