php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46410 Assignment does not properly evaluate to reference
Submitted: 2008-10-29 04:57 UTC Modified: 2014-10-12 14:36 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jbleau at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-10-29 04:57 UTC] jbleau at gmail dot com
Description:
------------
Assignments which should otherwise evaluate to references of the l-value do not properly do so in some situations, but do in others.

Reproduce code:
---------------
1. echo ($x = 5)--;
2. echo ($x = Array(3))[0];
3. echo ($x = ($y = 3));

I presume this is also related:

4.
function foo(){ return Array(3); }
echo (foo())[0];

Expected result:
----------------
1. 4
2. 3
3. 3
4. 3

Actual result:
--------------
1. Parser chokes on T_DEC
2. Parser chokes on [
3. Works correctly, 3 is assigned to $x and $y and printed.
4. Parser chokes on [

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 21:52 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2014-10-12 14:36 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2014-10-12 14:36 UTC] nikic@php.net
2., 3. and 4. will work in PHP 7.
1. does not work and should not work. (Assignments in PHP return rvalues.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 16:01:29 2024 UTC