Re: [RFC] Generalize support of negative string offsets

From: Date: Mon, 01 Feb 2016 22:08:46 +0000
Subject: Re: [RFC] Generalize support of negative string offsets
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-91052@lists.php.net to get a copy of this message
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 this is just guesswork, with a typo being >> a reasonable assumption. > > The problem is that while it is generally understood, it's generally > understood wrongly. $str[$offset] is not the same operation as > $array[$offset]. There are many subtle differences. So while at the > first sight it's similar, it leads to "understanding" that is only going > to harm one in the future, when it turns out you really had wrong idea. > I think it's much better to instill the right idea from the start, even > if it means one has to take a brief look in the manual. String offset is > *not* the same as array access. > >> 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 think deprecating it was a mistake and give how much semantic load [] > carries - array access, array constructor, now there's proposal to make > it used in deconstructing too - adding string offset to it looks like > bad idea. Different things should use different syntax, as much as possible. > Yup, you do have a good point here. Regards //Björn Larsson

« previous php.internals (#91052) next »