On 20/11/13 21:38, Yasuo Ohgaki wrote:
Hi Nikita,
On Thu, Nov 21, 2013 at 12:26 AM, Nikita Popov wrote:

The current behavior is that anything "falsey" (e.g. null, false and the
empty string) is silently cast to array when an array operation is applied
to it. I don't like that behavior, but it's somewhat internally consistent
now. Changing it for strings *only* seems a bit weird.

Persuasive argument.
I prefer to change the behavior if I have to choose, though.

$a = ''; // empty string
$a[10] = 'a';
echo $a; // "Array"
Just my 2 cents, but that definitely looks like a situation that might
crop up in real code unintentionally, and it violates the Principle of
Least Astonishment IMO. Consider a hypothetical function which returns a
modified string. If we've ended up with an empty string being passed
into it, then it suddenly returning an Array is not what you expect, and
might horribly break code that assumes the result won't be a string.

Andrea Faulds

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 10 | next ›
Discussion Overview
groupphp-internals @
postedNov 19, '13 at 11:48p
activeNov 22, '13 at 1:44a



site design / logo © 2022 Grokbase