dmitry

Dmitry Stogov , from Zend Technologies
(user votes do not necessarily reflect their company's views)

Contents

PHP RFC: Fix list() behavior inconsistency

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

PHP7

Implementation

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).

https://github.com/php/php-src/commit/7c7b9184b1fdf7add1715079f22241bc1185fcb0

Votes

An option needs 2/3 votes to win

Fix list() behavior inconsistency? (100% approved)
User Vote
ab Enable string handling in all cases
aharvey Enable string handling in all cases
ajf Disable string handling in all cases
auroraeosrose Enable string handling in all cases
bukka Enable string handling in all cases
bwoebi Enable string handling in all cases
datibbaw Disable string handling in all cases
daverandom Enable string handling in all cases
derick Enable string handling in all cases
dmitry Enable string handling in all cases
fmk Enable string handling in all cases
gwynne Disable string handling in all cases
hywan Disable string handling in all cases
jedibc Disable string handling in all cases
kalle Disable string handling in all cases
kassner Disable string handling in all cases
keyur Disable string handling in all cases
klaussilveira Disable string handling in all cases
krakjoe Enable string handling in all cases
laruence Enable string handling in all cases
leigh Disable string handling in all cases
levim Enable string handling in all cases
lstrojny Disable string handling in all cases
mbeccati Disable string handling in all cases
mike Disable string handling in all cases
nikic Enable string handling in all cases
pajoye Disable string handling in all cases
patrickallaert Disable string handling in all cases
pierrick Enable string handling in all cases
rasmus Disable string handling in all cases
rdlowrey Enable string handling in all cases
remi Disable string handling in all cases
stas Enable string handling in all cases