Bug #17794 Updated: Setting a reference and value on one line
| From: | mfischer@php.net | Date: | Mon, 17 Jun 2002 04:35:58 +0000 |
| Subject: | Bug #17794 Updated: Setting a reference and value on one line | ||
| References: | 1 | Groups: | php.bugs php.doc |
| Request: | Send a blank email to php-bugs+get-10822@lists.php.net to get a copy of this message | ||
ID: 17794
Updated by: mfischer@php.net
Reported By: greg@mtechsolutions.ca
Status: Open
-Bug Type: Scripting Engine problem
+Bug Type: Documentation problem
Operating System: should be independent
PHP Version: 4.1.2
New Comment:
You can't assign a value to a reference expression which is exactly
what you try to do:
&$b = 1;
The same applies for the array operator.
Moving it over to a documentation problem so the manual outlines this
better.
Previous Comments:
------------------------------------------------------------------------
[2002-06-16 23:51:16] greg@mtechsolutions.ca
Since you can do:
$a = $b = 1;
It is only natural to assume you can also do:
$a = &$b = 1;
However, this returns a parse error. Should it not return a refernce to
$b ?
Although this (simple) example seems stupid, the reason this is a
problem is when you involve arrays (and in my case, objects):
$a = &$b[] = new Object();
I want to add a new object into $b, but I just want it to go to a new
element number, without having to iterate through (which is currently
the only work-around I can think of).
At the same time, I need a reference to that object stored in another
variable. I can't make a temporary object, as it will be lost (only the
object in the $b array is stored permenantly) and it can't be a copy of
the object, it has to be the specific instance stored in $b.
If this has been fixed in ZE2, please disregard.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17794&edit=1