Bug #75629 [Fbk->NoF]: Object property references are replaced by references created in functions
| From: | php-bugs at lists dot php dot net | Date: | Sun, 09 Dec 2018 04:22:04 +0000 |
| Subject: | Bug #75629 [Fbk->NoF]: Object property references are replaced by references created in functions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218347@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75629&edit=1
ID: 75629
Updated by: php-bugs@lists.php.net
Reported by: ocramius@php.net
Summary: Object property references are replaced by references
created in functions
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Linux x64
PHP Version: Irrelevant
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2018-06-24 04:25:39] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
------------------------------------------------------------------------
[2017-12-05 15:28:51] ocramius@php.net
As discussed with Nikic, this issue is likely a misunderstanding in how references work. References
are bi-directional, and have to be maintained until necessary.
In the test case above, the reference becomes unnecessary as soon as the closure execution ends, but
it is to be kept when pushing it to an array.
This specific line is actually acting on a reference, and writing a clone to a reference, therefore
overwriting both objects:
$this->referencedProperty = clone $this->referencedProperty
A solution here is to de-reference the value by moving the reference:
```
$ref = & $this->referencedProperty;
unset($this->referencedProperty);
$this->referencedProperty = clone $ref;
```
I'm still not convinced that this is right, as it basically makes references a complete
nightmare to work it (not that it was a pleasure before this).
------------------------------------------------------------------------
[2017-12-05 12:00:55] ocramius@php.net
@nikic two incorrect things are going on here:
1. the referencedProperty is cloned too here (via __clone), so it should
be a new instance anyway
2. the Container#$referencedProperty is never a reference itself, but it is passed by
reference to the $loadFieldByReference() closure and stored in $references
------------------------------------------------------------------------
[2017-12-05 11:04:34] nikic@php.net
Try clarify, is the behavior you object to the fact that PHP preserves references while cloning? https://3v4l.org/c4iov
------------------------------------------------------------------------
[2017-12-05 09:24:11] ocramius@php.net
Causes https://github.com/Ocramius/ProxyManager/pull/396
(original source of the bug)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=75629
--
Edit this bug report at https://bugs.php.net/bug.php?id=75629&edit=1