Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104758 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82698 invoked from network); 15 Mar 2019 21:02:17 -0000 Received: from unknown (HELO mail-lf1-f68.google.com) (209.85.167.68) by pb1.pair.com with SMTP; 15 Mar 2019 21:02:17 -0000 Received: by mail-lf1-f68.google.com with SMTP id a132so6053489lfa.13 for ; Fri, 15 Mar 2019 10:52:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cCB33BrZkkp1Isjhx5Bbhb0zSKm6wkLFEkufezqjfcM=; b=mjZ2Rj3p1iAYcm2ae3ivcV956W4ybWaB1+SGkDLfgdfpsvmw0FmeZLuZLzZlKOOqYq nJvHYjFASaYXTMd3BJ++lQJaMQ9kWXxsWVGEF5gh8NkKSb/UguMdjjJnyz4HgPtsW8QI fxQhEzzPYu9RFSTezAR5AjKmP5vzD0YgMEx7oIehNCFwiKWQLUVG0+bjbbRalcoKuuXm LV2u7YJO8+1y0a6wncwgdKg0GsBA+3d+YHv6fCjvnrlAacyOnRYmA2ocqDFaGsBjVV+q JZQE04S8pz6KwnT23EPIlqyXepyLnxvwDLcejta9L/bKyxNX9/qO2JKf/0FeVJHi7lUY d5MQ== X-Gm-Message-State: APjAAAUcBD9EIl44a4AUEGaUepPrt8JAbaJMHXI/1R0zMOBd25O8cyWH V1SqVy1Jcq9OZWDQjnS7oluDFjupsykos5fVuqs= X-Google-Smtp-Source: APXvYqxd5ogl5I9vGn5XP5C32rUUrHl3FRtWQoDhlSwueFUXtwFs1ceaYN6CIiEYMnXoCeMBJBhVa4SuDlqTAkspnbs= X-Received: by 2002:a19:740e:: with SMTP id v14mr2841026lfe.94.1552672375609; Fri, 15 Mar 2019 10:52:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 15 Mar 2019 11:52:39 -0600 Message-ID: To: Kalle Sommer Nielsen Cc: Nikita Popov , Andrey O Gromov , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Proposal for deprecate alternate syntax(curly braces) for array and string access From: levim@php.net (Levi Morrison) On Fri, Mar 15, 2019 at 10:31 AM Kalle Sommer Nielsen wrote: > > Den fre. 15. mar. 2019 kl. 17.06 skrev Nikita Popov : > > 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 > kalle@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.