PHP :: Bug #67908 :: list($a, $b) = $a broken.
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
 [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-2018 The PHP Group
All rights reserved.
Last updated: Tue Aug 14 08:01:25 2018 UTC