Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-16 Thread Yasuo Ohgaki
On Wed, Feb 17, 2016 at 9:32 AM, François Laupretre wrote: > > Le 17/02/2016 00:26, Yasuo Ohgaki a écrit : >> >> I noticed one issue on {} >> https://bugs.php.net/bug.php?id=71611 >> >> echo "${str{1}}"; >> >> raises syntax error while >> >> echo "{$str{1}}"; >> >> works. Is

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-16 Thread François Laupretre
Hi, Le 17/02/2016 00:26, Yasuo Ohgaki a écrit : I noticed one issue on {} https://bugs.php.net/bug.php?id=71611 echo "${str{1}}"; raises syntax error while echo "{$str{1}}"; works. Is this addressed? No, this is a different problem. This RFC just adds support for negative index values.

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-16 Thread Yasuo Ohgaki
Hi Francois, I noticed one issue on {} https://bugs.php.net/bug.php?id=71611 echo "${str{1}}"; raises syntax error while echo "{$str{1}}"; works. Is this addressed? -- Yasuo Ohgaki yohg...@ohgaki.net On Sun, Jan 24, 2016 at 12:45 AM, François Laupretre wrote: > Hi, > >

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-16 Thread François Laupretre
Le 15/02/2016 04:49, Stanislav Malyshev a écrit : Hi! This fix has been merged into master (targeting 7.1), thanks! I'm not sure that was such a good idea (sorry, didn't have time to write about it before the weekend). Introducing a new warning into previously working code is a BC break, and

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-15 Thread Arvids Godjuks
On Mon, 15 Feb 2016 08:16 Yasuo Ohgaki wrote: > Hi all, > > On Mon, Feb 15, 2016 at 12:49 PM, Stanislav Malyshev > wrote: > >> Another issue mentioned in this thread is the spurious array conversion > >> that happens for empty strings. We have an

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-14 Thread Yasuo Ohgaki
Hi Pierre, On Mon, Feb 15, 2016 at 4:01 PM, Pierre Joye wrote: > On Feb 15, 2016 1:15 PM, "Yasuo Ohgaki" wrote: >> >> Hi all, >> >> On Mon, Feb 15, 2016 at 12:49 PM, Stanislav Malyshev >> wrote: >> >> Another issue mentioned in

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-14 Thread Pierre Joye
On Feb 15, 2016 1:15 PM, "Yasuo Ohgaki" wrote: > > Hi all, > > On Mon, Feb 15, 2016 at 12:49 PM, Stanislav Malyshev > wrote: > >> Another issue mentioned in this thread is the spurious array conversion > >> that happens for empty strings. We have an

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-14 Thread Yasuo Ohgaki
Hi all, On Mon, Feb 15, 2016 at 12:49 PM, Stanislav Malyshev wrote: >> Another issue mentioned in this thread is the spurious array conversion >> that happens for empty strings. We have an existing bug report for this: >> https://bugs.php.net/bug.php?id=53432 I've created a

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-14 Thread Stanislav Malyshev
Hi! > This fix has been merged into master (targeting 7.1), thanks! I'm not sure that was such a good idea (sorry, didn't have time to write about it before the weekend). Introducing a new warning into previously working code is a BC break, and one that wasn't even discussed in its own thread.

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-14 Thread Nikita Popov
On Fri, Feb 12, 2016 at 12:44 AM, François Laupretre wrote: > Le 11/02/2016 17:25, Andrea Faulds a écrit : > >> Hi François, >> >> François Laupretre wrote: >> >>> String offsets are full of oddities : >>> >>> $str = "abc"; >>> $str{0} = ''; >>> var_dump($str); // -> string(3)

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-12 Thread Lester Caine
On 11/02/16 18:07, Stanislav Malyshev wrote: >> It does not worth the effort having other RFCs for >> > - $str{} = 'string' > Correct, because nobody needs it and it is a bad idea. > >> > I agree small changes are easier to review, but it may leave lots of >> > obvious inconsistency in PHP. We

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Rowan Collins
Nikita Popov wrote on 11/02/2016 13:14: The issue here is not an inherent problem with string offsets, it's simply yet another artifact of PHP's overly lenient nature. If I create an IntArray class that implements ArrayAccess, I don't think you would be much surprised if doing $intArray[$i] =

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Yasuo Ohgaki
Hi Stas, On Thu, Feb 11, 2016 at 4:08 PM, Stanislav Malyshev wrote: >> RFC must maintain consistency across existing features/specifications, > > There's a lot of things people call "consistency", apparently. I don't > see inventing new syntax for doing concatenation to have

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread François Laupretre
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,

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Christoph Becker
On 11.02.2016 at 12:12, Yasuo Ohgaki wrote: > Anyway, all of us know that main source of complaints about PHP is lack > of consistency. Inconsistent APIs across modules are acceptable. It's > modules after all. However, basic language constructs like [] and {} are > better to have

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Rowan Collins
Christoph Becker wrote on 11/02/2016 12:16: 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

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread François Laupretre
Le 11/02/2016 13:46, Rowan Collins a écrit : Christoph Becker wrote on 11/02/2016 12:16: 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

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread François Laupretre
String offsets are full of oddities : $str = "abc"; $str{0} = ''; var_dump($str); // -> string(3) "bc" (read as "\0bc") Assigning an empty string to a string offset inserts a null byte because the string length is not checked in zend_assign_to_string_offset(). I see this as a bug. IMO, this

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Nikita Popov
On Thu, Feb 11, 2016 at 1:46 PM, Rowan Collins wrote: > Christoph Becker wrote on 11/02/2016 12:16: > >> 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

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Andrea Faulds
Hi François, François Laupretre wrote: String offsets are full of oddities : $str = "abc"; $str{0} = ''; var_dump($str); // -> string(3) "bc" (read as "\0bc") Assigning an empty string to a string offset inserts a null byte because the string length is not checked in

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread François Laupretre
Le 11/02/2016 17:25, Andrea Faulds a écrit : Hi François, François Laupretre wrote: String offsets are full of oddities : $str = "abc"; $str{0} = ''; var_dump($str); // -> string(3) "bc" (read as "\0bc") Assigning an empty string to a string offset inserts a null byte because the string

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Stanislav Malyshev
Hi! > Anyway, all of us know that main source of complaints about PHP is lack > of consistency. Inconsistent APIs across modules are acceptable. It's > modules after all. However, basic language constructs like [] and {} are > better to have predictable/consistent behaviors. i.e. how it works,

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-11 Thread Stanislav Malyshev
Hi! > Just having a different syntax, writing $foo{0} = 'zzz' instead of $foo[0] > = 'zzz' does not make the implicit truncation behavior any more obvious or > reasonable. If we want to actually make it less confusing, what we should It makes it clear the operation you are dealing with is not

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread Dan Ackroyd
On 10 February 2016 at 14:34, François Laupretre wrote: > Hi, > > I just added support for '[]' on strings and '{}' to the PR. > > Examples : > > $string[] = 'a'; // equivalent to : $string[strlen($string)] > > $string{} = 'a'; // For consistency Unless I'm missing some

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread François Laupretre
Le 10/02/2016 15:34, Dan Ackroyd a écrit : On 10 February 2016 at 07:00, Yasuo Ohgaki wrote: Additional comment on this php > $v=array(1,2,3); php > $v .= 'abc'; I think $v .= 'abc' should not destroy array variable. It's minor issue, though. That is the current

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread François Laupretre
Hi, I just added support for '[]' on strings and '{}' to the PR. Examples : $string[] = 'a'; // equivalent to : $string[strlen($string)] $string{} = 'a'; // For consistency With this change, AFAIK, '{}' and '[]' notations are handled exactly the same way (the only difference was that the

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread Dan Ackroyd
On 10 February 2016 at 07:00, Yasuo Ohgaki wrote: > Additional comment on this > > php > $v=array(1,2,3); > php > $v .= 'abc'; > > I think $v .= 'abc' should not destroy array variable. It's minor issue, > though. That is the current behaviour. Trying to slip "bug fixes"

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread Yasuo Ohgaki
Hi Stas, On Thu, Feb 11, 2016 at 3:27 PM, Stanislav Malyshev wrote: > >> I just added support for '[]' on strings and '{}' to the PR. >> >> Examples : >> >> $string[] = 'a'; // equivalent to : $string[strlen($string)] >> >> $string{} = 'a'; // For consistency > > That's

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread Stanislav Malyshev
Hi! > I just added support for '[]' on strings and '{}' to the PR. > > Examples : > > $string[] = 'a'; // equivalent to : $string[strlen($string)] > > $string{} = 'a'; // For consistency That's probably not a good idea, and certainly is not good for the RFC - the patch now does two unrelated

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread Stanislav Malyshev
Hi! > RFC must maintain consistency across existing features/specifications, There's a lot of things people call "consistency", apparently. I don't see inventing new syntax for doing concatenation to have anything to do with consistency. > make things worse certainly. Making patch and/or RFC

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-10 Thread François Laupretre
Le 11/02/2016 07:27, Stanislav Malyshev a écrit : Hi! I just added support for '[]' on strings and '{}' to the PR. Examples : $string[] = 'a'; // equivalent to : $string[strlen($string)] $string{} = 'a'; // For consistency That's probably not a good idea, and certainly is not good for the

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-09 Thread Yasuo Ohgaki
On Wed, Feb 10, 2016 at 3:51 PM, Yasuo Ohgaki wrote: > Behavior regarding array. (a bit off topic, but error level should > match with new string '{}' errors.) > > php > error_reporting(-1); > php > $v=array(); > php > $v .= 'abc'; > > Notice: Array to string conversion in php

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-09 Thread Yasuo Ohgaki
Hi Francois, On Tue, Feb 9, 2016 at 12:09 AM, François Laupretre wrote: > Slightly off-topic but, as I was looking for the way to add support for > '$str[]=' assignments, I found something strange. > > Just for curiosity, does someone know a reason for this : > > $str = "abc";

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-08 Thread Rowan Collins
Nikita Popov wrote on 06/02/2016 15:16: In any case, while this is no doubt an interesting question, and one we should resolve, it is tangential to this RFC and this RFC should make no recommendations either way. I would prefer not to be forced to vote against this RFC due to the inclusion of

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-08 Thread François Laupretre
Hi, Slightly off-topic but, as I was looking for the way to add support for '$str[]=' assignments, I found something strange. Just for curiosity, does someone know a reason for this : $str = "abc"; $str[1]="z"; var_dump($str); // -> string(3) "zbc" -> Expected $str = ""; // Empty string

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-07 Thread François Laupretre
Le 06/02/2016 16:16, Nikita Popov a écrit : In any case, while this is no doubt an interesting question, and one we should resolve, it is tangential to this RFC and this RFC should make no recommendations either way. I would prefer not to be forced to vote against this RFC due to the inclusion

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-06 Thread Stanislav Malyshev
Hi! > if it means one has to take a brief look in the manual. String offset is > *not* the same as array access. > > > What are these subtle differences? Negative indexes, string indexes. Array offset is a variable, so it can be used by-ref, but string offset can not. You can

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-06 Thread Nikita Popov
On Mon, Feb 1, 2016 at 10:06 PM, Stanislav Malyshev wrote: > Hi! > > > I strongly disagree with this. $str[$offset] is well-recognized, > > generally understood syntax that does not require familiarity with > > language peculiarities. $str{$offset} might be clear to a Perl >

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-01 Thread Levi Morrison
> We should be deprecating this alternative syntax instead of recommending > its use. I was under the impression that we *were* already discouraging its > use and it has already been temporarily deprecated. I agree with Nikita. I think we should be deprecating and removing `{}` access in favor of

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-01 Thread Stanislav Malyshev
Hi! > I strongly disagree with this. $str[$offset] is well-recognized, > generally understood syntax that does not require familiarity with > language peculiarities. $str{$offset} might be clear to a Perl > programmer, but to anyone else this is just guesswork, with a typo being > a reasonable

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-01 Thread Björn Larsson
Den 2016-02-01 kl. 22:06, skrev Stanislav Malyshev: > Hi! > >> I strongly disagree with this. $str[$offset] is well-recognized, >> generally understood syntax that does not require familiarity with >> language peculiarities. $str{$offset} might be clear to a Perl >> programmer, but to anyone else

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-01 Thread Julien Pauli
On Sun, Jan 31, 2016 at 11:14 PM, Stanislav Malyshev wrote: > Hi! > >> The only concern I have is that support of negative indexing will break >> symmetry with (proper) arrays, where we cannot support negative indexing. > > I think that was the main source of objections to

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-01 Thread François Laupretre
Le 31/01/2016 23:14, Stanislav Malyshev a écrit : Hi! The only concern I have is that support of negative indexing will break symmetry with (proper) arrays, where we cannot support negative indexing. I think that was the main source of objections to this proposal in the past. However, as one

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-02-01 Thread Nikita Popov
On Sun, Jan 31, 2016 at 11:14 PM, Stanislav Malyshev wrote: > Hi! > > > The only concern I have is that support of negative indexing will break > > symmetry with (proper) arrays, where we cannot support negative indexing. > > I think that was the main source of objections to

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-01-31 Thread Nikita Popov
On Sat, Jan 23, 2016 at 4:45 PM, François Laupretre wrote: > Hi, > > Starting discussion about https://wiki.php.net/rfc/negative-string-offsets > > Please read and comment. > Just dropping by with a +1 on this proposal. Consistent support is always good. The only concern I

Re: [PHP-DEV] [RFC] Generalize support of negative string offsets

2016-01-31 Thread Stanislav Malyshev
Hi! > The only concern I have is that support of negative indexing will break > symmetry with (proper) arrays, where we cannot support negative indexing. I think that was the main source of objections to this proposal in the past. However, as one might say, string offsets are already not

[PHP-DEV] [RFC] Generalize support of negative string offsets

2016-01-23 Thread François Laupretre
Hi, Starting discussion about https://wiki.php.net/rfc/negative-string-offsets Please read and comment. Regards François -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php