php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67908 list($a, $b) = $a broken.
Submitted: 2014-08-26 12:23 UTC Modified: 2014-08-26 20:04 UTC
From: arjen at react dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: master-Git-2014-08-26 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: arjen at react dot com
New email:
PHP Version: OS:

 

 [2014-08-26 12:23 UTC] arjen at react dot com
Description:
------------
Probably in AST refactor.

Test script:
---------------
$a = array('a', 'b');
list($a, $b) = $a;
var_dump($a, $b);

Expected result:
----------------
string(1) "a"
string(1) "b"


Actual result:
--------------
string(1) "a"
string(0) ""


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-26 18:07 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-08-26 18:07 UTC] requinix@php.net
That is exactly it except the change is desired; AST makes list() assign left to right instead of the current behavior of right to left. Which, if I may say so, makes much more sense and removes one of the oddest quirks in PHP.
https://wiki.php.net/rfc/abstract_syntax_tree#changes_to_list

Besides, the documentation specifically warns about that kind of structure resulting in undefined behavior.
http://php.net/manual/en/function.list.php#refsect1-function.list-notes

If you haven't seen it already, you may be interested in reading the thread about AST on the internals mailing list. The change to list() was (briefly) mentioned.
http://php.markmail.org/thread/br4ixewsnqitrx3n
 [2014-08-26 20:04 UTC] arjen at react dot com
I see now.

I followed the RFC, but this specific case was mentioned and added to the RFC changes list  while I was on holidays. So I missed it, sorry!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC