PHP RFC: Fix list() behavior inconsistency
- Version: 1.0
- Date: 2014-09-11
- Author: Dmitry Stogov, email@example.com
- Status: Implemented (in PHP 7)
- First Published at: http://wiki.php.net/rfc/fix_list_behavior_inconsistency
According to PHP documentation list() construct doesn't work with strings. However in some cases it works.
$ php -r 'list($a,$b) = "aa";var_dump($a,$b);' NULL NULL $ php -r '$a="ab"; list($a,$b) = $a; var_dump($a,$b);' string(1) "a" string(1) "b"
This behavior caused by implementation feature and wasn't made on purpose.
Make list() behave with strings in consistent way. There are two options:
Disable string handling in all cases
This will disable undocumented feature and it may break some existing PHP code.
Enable string handling in all cases
This will make the following code work.
list($a,$b) = "str";
Instead of assignment NULL into $a and $b, it'll assign 's' and 't' characters. However, it also may break some existing PHP code.
Backward Incompatible Changes
Both options may affect existing PHP code.
Proposed PHP Version(s)
This project requires a 2/3 majority, between first and second or third options.
Voting started on 2014-09-25 and ends 2014-10-02.
Support for strings has been removed for all cases. Support for
ArrayAccess has been added for all cases (previously it was not supported for temporary variables).