# [RFC] Fix list() behavior inconsistency

- Thread: https://externals.io/message/77150
- Original archive: https://news-web.php.net/php.internals/77150
- Started by Dmitry Stogov on 2014-09-11T09:59:43+00:00
- Messages: 6
- RFC: Fix list() behavior inconsistency (Implemented (PHP 7.0)) — https://externals.io/rfc/fix_list_behavior_inconsistency.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #77150 — Dmitry Stogov — 2014-09-11T09:59:43+00:00

URL: https://externals.io/message/77150#77150

Hi,

Please take a look and make your opinion.

https://wiki.php.net/rfc/fix_list_behavior_inconsistency

This inconsistency might be interpreted like a bug, but fixing it might
break existing PHP code (at least my attempt to fix it in documented way
broke few phpt tests).

Thanks. Dmitry.

---

## #77172 — Stas Malyshev — 2014-09-14T06:48:06+00:00

URL: https://externals.io/message/77150#77172 · In reply to: #77150

Hi!

> Please take a look and make your opinion.
> 
> https://wiki.php.net/rfc/fix_list_behavior_inconsistency
> 
> This inconsistency might be interpreted like a bug, but fixing it might
> break existing PHP code (at least my attempt to fix it in documented way
> broke few phpt tests).

I think it makes sense to make list($a, $b, ...) = <something> to mean:
$a = <something>[0]
$b = <something>[1]
...etc...

This is how it works in most cases, not sure why it doesn't work when
<something> is a string literal, but I think it should work the same too.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/

---

## #77173 — Lester Caine — 2014-09-14T07:54:25+00:00

URL: https://externals.io/message/77150#77173 · In reply to: #77172

> > […]
> I think it makes sense to make list($a, $b, ...) = <something> to mean:
> $a = <something>[0]
> $b = <something>[1]
> ...etc...
> 
> This is how it works in most cases, not sure why it doesn't work when
> <something> is a string literal, but I think it should work the same too.

Isn't this just a side affect of making a simple string also look like
an array? One has to assume first that what is returned is a simple byte
string array while currently is IS possible that it will contain unicode
characters? So should it not be looked at n the context of the whole
PHP7 discussion rather than trying to fix more edge cases in isolation?

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

---

## #77190 — Rowan Collins — 2014-09-14T17:26:24+00:00

URL: https://externals.io/message/77150#77190 · In reply to: #77173

> One has to assume first that what is returned is a simple byte
> string array while currently is IS possible that it will contain unicode
> characters?

Well, currently, every single string function in PHP treats a string as 
a simple byte array, apart from those in the mbstring and intl extensions.

What's more, there isn't really a single meaning of the term "Unicode 
character" - at its simplest, there are code points, but they're not 
necessarily the most useful unit; as I mentioned before [1], people 
often actually want to work with "grapheme clusters", what a writer of 
the language would consider "a single character".

If more integrated Unicode support is ever added, it will presumably be 
in the form of a new data type; if that type implements $foo[0] to mean 
"first grapheme cluster", then it would be natural for list($a,) = $foo 
to do the same. But there is no reason for that to stop list($a,) = $foo 
being equivalent to $foo[0] for existing strings, and mean "first byte".

[1] http://news.php.net/php.internals/72914

-- 
Rowan Collins
[IMSoP]

---

## #77283 — Derick Rethans — 2014-09-17T11:00:39+00:00

URL: https://externals.io/message/77150#77283 · In reply to: #77150

> Please take a look and make your opinion.
> 
> https://wiki.php.net/rfc/fix_list_behavior_inconsistency
> 
> This inconsistency might be interpreted like a bug, but fixing it might
> break existing PHP code (at least my attempt to fix it in documented way
> broke few phpt tests).

But at least your option "Enable string handling in all cases" makes 
additional things work, instead of making things *no longer* work.

I realize that:
	list($a,$b) = "aa";var_dump($a,$b);
Will now start returning something else than NULL, but I would almost 
consider that a bug. I would definitely elect to vote for "Enable string 
handling in all cases" as it IMO actually fixes something.

cheers,
Derick

---

## #77284 — Dmitry Stogov — 2014-09-17T12:23:58+00:00

URL: https://externals.io/message/77150#77284 · In reply to: #77283

Both decisions make sense. I'm indifferent which one to make.
Just not to keep the undocumented inconsistency :)

Thanks. Dmitry,



> 
>
> > […]
>
> But at least your option "Enable string handling in all cases" makes
> additional things work, instead of making things *no longer* work.
>
> I realize that:
>         list($a,$b) = "aa";var_dump($a,$b);
> Will now start returning something else than NULL, but I would almost
> consider that a bug. I would definitely elect to vote for "Enable string
> handling in all cases" as it IMO actually fixes something.
>
> cheers,
> Derick
