On Fri, Mar 15, 2019 at 10:31 AM Kalle Sommer Nielsen <ka...@php.net> wrote:
>
> Den fre. 15. mar. 2019 kl. 17.06 skrev Nikita Popov <nikita....@gmail.com>:
> > I'm okay with this. This syntax has already been deprecated once, though it
> > was reverted for reasons I don't remember.
> >
> > There are some people using this syntax to distinguish between array and
> > string access. It's a nice thought, but as the vast majority of code
> > doesn't make this distinction (I think the only time I saw this in recent
> > years was inside some old PEAR code), it's not really a useful indicator.
>
> I personally use it because I like to quickly tell if I am doing an
> operation on a string or array, it is eye candy and makes a lot of
> sense. I think if anything the two syntaxes should be decoupled
> instead.
>
> From a usage PoV, then from personal experience (outside my own
> projects), I have seen many usages of this syntax, even as late as my
> current company with a growing codebase that is nearing 1.1m LoC, I
> have seen this syntax used countless of times. In fact I don't think I
> have been working with a code base where I have not seen this syntax
> used.
>
> I have asked fellow developers around in my community today and they
> have no strong opinion on either, but do like the distinction between.
>
> > The rarity of its use also makes it rather confusing. While $foo[$x] is
> > well established as an array or string offset (or for that matter,
> > ArrayObject) access and will be recognized by any programmer coming from
> > any number of programming languages, $foo{$x} certainly is not, and is a
> > WTF moment for people who don't happen to personally use this syntax.
> >
> > I'd prefer to phase out this syntax entirely and not reuse it for any other
> > purpose. Reusing syntax is generally a not so good idea, because it means
> > that the same syntax has different meaning in different PHP version.
>
>
> For me personally it is a huge -1, if anything I would like the
> string[] syntax decoupled.
>
>
> --
> regards,
>
> Kalle Sommer Nielsen
> ka...@php.net
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php

Four thoughts:

  1. I cannot think of *any* reason to separate them. If you want to
make sure you are indexing a string, *do a type check*, not bake `{}`
into only working on strings.
  2. While Kalle says pretty much every codebase they've seen lately
has used `{}` for indexing, I have *never* seen a codebase that used
it.
  3. In any case, usage of `{}`  can be migrated to `[]` by a style
fixer, right?
  4. Even if we deprecate `{}`, I don't think we'd be in any hurry to
remove it, though with an automatic fixer this seems doable, if we
care to do it at all.

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

Reply via email to