note 118852 added to mysqli-result.fetch-object
| From: | object-array at gmail dot com | Date: | Wed, 17 Feb 2016 08:56:37 +0000 |
| Subject: | note 118852 added to mysqli-result.fetch-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204962@lists.php.net to get a copy of this message | ||
Please mind the difference between objects and arrays in PHP>=5: arrays are by value while
objects are by reference.
<?
$o = mysqli_fetch_object($res);
$o1 = $o;
$o1->value = 10;
$a = mysqli_fetch_array($res);
$a1 = $a;
$a1['value'] = 10;
echo $o->value; // 10
echo $a['value']; // (original value from db)
?>
Should same behaviour be intended, the object needs to be cloned:
<?
$o1 = clone $o;
?>
More about object cloning:
http://php.net/manual/en/language.oop5.cloning.php
----
Server IP: 72.52.91.14
Probable Submitter: 217.91.62.164
----
Manual Page -- http://php.net/manual/en/mysqli-result.fetch-object.php
Edit -- https://master.php.net/note/edit/118852
Del: integrated -- https://master.php.net/note/delete/118852/integrated
Del: useless -- https://master.php.net/note/delete/118852/useless
Del: bad code -- https://master.php.net/note/delete/118852/bad+code
Del: spam -- https://master.php.net/note/delete/118852/spam
Del: non-english -- https://master.php.net/note/delete/118852/non-english
Del: in docs -- https://master.php.net/note/delete/118852/in+docs
Del: other reasons-- https://master.php.net/note/delete/118852
Reject -- https://master.php.net/note/reject/118852
Search -- https://master.php.net/manage/user-notes.php