note 118851 added to mysqli-result.fetch-array
| From: | object-array at gmail dot com | Date: | Wed, 17 Feb 2016 08:55:48 +0000 |
| Subject: | note 118851 added to mysqli-result.fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204961@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-array.php
Edit -- https://master.php.net/note/edit/118851
Del: integrated -- https://master.php.net/note/delete/118851/integrated
Del: useless -- https://master.php.net/note/delete/118851/useless
Del: bad code -- https://master.php.net/note/delete/118851/bad+code
Del: spam -- https://master.php.net/note/delete/118851/spam
Del: non-english -- https://master.php.net/note/delete/118851/non-english
Del: in docs -- https://master.php.net/note/delete/118851/in+docs
Del: other reasons-- https://master.php.net/note/delete/118851
Reject -- https://master.php.net/note/reject/118851
Search -- https://master.php.net/manage/user-notes.php