note 83286 deleted from language.oop5.cloning by cmb
| From: | cmb@php.net | Date: | Sun, 10 Jul 2016 20:11:01 +0000 |
| Subject: | note 83286 deleted from language.oop5.cloning by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-205953@lists.php.net to get a copy of this message | ||
Note Submitter: alex dot offshore at gmail dot com
----
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