note 119724 added to functions.arguments

From: Date: Thu, 11 Aug 2016 07:05:17 +0000
Subject: note 119724 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-206258@lists.php.net to get a copy of this message
A function's argument that is an object, will have its properties modified by the function although you don't need to pass it by reference. <?php $x = new stdClass(); $x->prop = 1; function f ( $o ) // Notice the absence of & { $o->prop ++; } f($x); echo $x->prop; // shows: 2 ?> This is different for arrays: <?php $y = [ 'prop' => 1 ]; function g( $a ) { $a['prop'] ++; echo $a['prop']; // shows: 2 } g($y); echo $y['prop']; // shows: 1 ?> ---- Server IP: 72.52.91.14 Probable Submitter: 37.26.149.202 ---- Manual Page -- http://php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/119724 Del: integrated -- https://master.php.net/note/delete/119724/integrated Del: useless -- https://master.php.net/note/delete/119724/useless Del: bad code -- https://master.php.net/note/delete/119724/bad+code Del: spam -- https://master.php.net/note/delete/119724/spam Del: non-english -- https://master.php.net/note/delete/119724/non-english Del: in docs -- https://master.php.net/note/delete/119724/in+docs Del: other reasons-- https://master.php.net/note/delete/119724 Reject -- https://master.php.net/note/reject/119724 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206258) next »