Le 11/02/2016 13:16, Christoph Becker a écrit :

Appending to an array always adds a single element only, consider

   $a = [1,2,3];
   $a[] = [4,5];

The suggested syntax for strings would concatenate an arbitrary amount
of elements (characters) to a string.  IMHO, this would not be
consistent, but rather confusing.  The alternative interpretation to
append the first character only, would be confusing as well (besides
there would be issues with regard to multibyte character encodings).


Not exactly, the '$str[]' syntax I suggested would have worked the same as '$str[strlen($str)]': it would have appended the first character only. Concerns about multi-bytes characters are clearly out of scope, as all string offset operations handle bytes only.

Regarding consistency, I understand the arguments about the fact that string concatenation should be done using the '.' operator, but do you know that this is already supported :

$str="abc";
$str[3]='def';  // $str="abcd"
$str[10]='xyz'; // $str = "abc       x";

So, my feeling was that, since '$str[strlen($str)]' is supported, we *already* support concatenation using string offset syntax. So, supporting '[]' and '{}' as a shortcut for '[strlen($str)]' was just a small addition for a better consistency and a more intuitive behavior.

Stas and Yasuo are both right. It is not exactly related to negative string offsets but, on the other side, I probably won't bother opening an RFC for such a small change. That's why, if there had been a consensus, I would have added it to the current RFC.

Regards

François



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to