Doc #61513 [Opn->Csd]: clone operator precedence is wrong
| From: | cmb@php.net | Date: | Fri, 14 Aug 2020 08:57:14 +0000 |
| Subject: | Doc #61513 [Opn->Csd]: clone operator precedence is wrong | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17785@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61513&edit=1
ID: 61513
Updated by: cmb@php.net
Reported by: antickon at gmail dot com
Summary: clone operator precedence is wrong
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: 5.3.10
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Fixed with <http://svn.php.net/viewvc?view=revision&revision=347901>.
Previous Comments:
------------------------------------------------------------------------
[2018-01-10 10:32:40] pasindu@php.net
So is the suggestions here to remove "[" from the docs or maybe add note about this?
------------------------------------------------------------------------
[2012-03-29 13:48:56] antickon at gmail dot com
Even if [ is an amalgam of syntactic constructs, precedence and associativity are
properties it appears to have. Having it correctly documented is absolutely
preferable.
------------------------------------------------------------------------
[2012-03-29 13:37:19] nikic@php.net
clone/new are defined with higher precedence in the parser. But there is no general
expr [
dim_offset ] rule (only specific rules for various variable syntaxes), so it can't be
interpreted as (clone $a)[0].
Hard to say what one can do about this in the docs. Maybe removing [ from the list might be a viable
option. Variable offset access is kinda outside the normal precedence rules.
------------------------------------------------------------------------
[2012-03-26 14:33:49] antickon at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.operators.precedence
---
According to the Operator Precedence table, the clone operator has higher
precedence than [.
This would mean clone $arraylike[0] is evaluated as ( clone $arraylike )[0], but
it seems that the implementation does clone ( $arraylike[0] ). I think this is
probably correct behavior, so I conclude the documentation is incorrect.
Test script:
---------------
$a = array( new stdClass() );
clone $a[0];
Expected result:
----------------
in this case, some type error at runtime since you can't clone an array
Actual result:
--------------
the object at offset 0 is cloned
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61513&edit=1