note 83286 added to language.oop5.cloning

From: Date: Mon, 19 May 2008 10:23:39 +0000
Subject: note 83286 added to language.oop5.cloning
Groups: php.notes 
Request: Send a blank email to php-notes+get-139515@lists.php.net to get a copy of this message
Remember that in PHP 5 ALL objects are assigned BY REFERENCE. <?php function foo($a) // notice that '&' near $a is missing { $a['bar'] = 10; } $x = array('bar' => 0); // built-in array() is not an object $y = new ArrayObject(array('bar' => 0)); echo "\$x['bar'] == ${x['bar']};\n\$y['bar'] == ${y['bar']};\n\n"; foo($x); foo($y); echo "\$x['bar'] == ${x['bar']};\n\$y['bar'] == ${y['bar']};\n"; ?> Output: $x['bar'] == 0; $y['bar'] == 0; $x['bar'] == 0; $y['bar'] == 10; Hope this will be useful. By the way, to determine whether the variable is compatible with ArrayAccess/ArrayObject see http://php.net/manual/en/function.is-array.php#48083 ---- Server IP: 195.54.192.44 Probable Submitter: 127.0.0.1 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.cloning.php Edit -- https://master.php.net/note/edit/83286 Del: integrated -- https://master.php.net/note/delete/83286/integrated Del: useless -- https://master.php.net/note/delete/83286/useless Del: bad code -- https://master.php.net/note/delete/83286/bad+code Del: spam -- https://master.php.net/note/delete/83286/spam Del: non-english -- https://master.php.net/note/delete/83286/non-english Del: in docs -- https://master.php.net/note/delete/83286/in+docs Del: other reasons-- https://master.php.net/note/delete/83286 Reject -- https://master.php.net/note/reject/83286 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139515) next »