Doc #61513 [Opn]: clone operator precedence is wrong
Edit report at https://bugs.php.net/bug.php?id=61513&edit=1
ID: 61513
User updated by: antickon at gmail dot com
Reported by: antickon at gmail dot com
Summary: clone operator precedence is wrong
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
Even if [ is an amalgam of syntactic constructs, precedence and associativity are
properties it appears to have. Having it correctly documented is absolutely
preferable.
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)