rfc:fix_list_behavior_inconsistency

This is an old revision of the document!


PHP RFC: Your Title Here

Introduction

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[0]="ab"; list($a,$b) = $a[0]; var_dump($a,$b);'
string(1) "a"
string(1) "b"

This behavior caused by implementation feature and wasn't made on purpose.

Proposal

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 'a' 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)

PHP7

Proposed Voting Choices

  • disable string handling in all cases
  • enable string handling in all cases

This project requires a 2/3 majority

Patches and Tests

The implementation is not really a problem.

rfc/fix_list_behavior_inconsistency.1410429232.txt.gz · Last modified: 2017/09/22 13:28 (external edit)