Bug #68145 [Opn->Nab]: For + Array declaration inside
| From: | requinix@php.net | Date: | Fri, 03 Oct 2014 17:18:30 +0000 |
| Subject: | Bug #68145 [Opn->Nab]: For + Array declaration inside | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187822@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68145&edit=1
ID: 68145
Updated by: requinix@php.net
Reported by: renzo dot disalvo at gmail dot com
Summary: For + Array declaration inside
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu 12.04 LTS (GNU/Linux 3.2
PHP Version: 5.5.17
Block user comment: N
Private report: N
New Comment:
There are many possible explanations for what happened and what you were seeing, and it may come
down to what getRandomQuestion() is returning and how it does that. My guess: since objects in PHP 5
are references and not copies, if you modify the same object over and over again then every instance
you had of that object will be affected too.
Previous Comments:
------------------------------------------------------------------------
[2014-10-03 15:52:51] renzo dot disalvo at gmail dot com
Ok resolved but I don't know if is a bug,
Never mix object and array mixed together.
The strange think the output was correct but outside of the for the array become corrupted.
R
------------------------------------------------------------------------
[2014-10-03 14:53:08] renzo dot disalvo at gmail dot com
Description:
------------
I'm trying to generate some values and after assign to the array,
The strange think is when I print out the output is totally different.
In the final array I can see duplicate, but the original assignment is unique.
Test script:
---------------
for ($i = 1; $i <= 10; $i++) {
$question = $this->getRandomQuestion();
print_r($question->data['name']); // return Correct Name
$arrQuestion[$i] = $question;
print_r($arrQuestion[$i]->data['name']); //Return Correct name
print_r("\n");
}
print_r($arrQuestion[1]); //Return Different Value
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68145&edit=1