Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115008 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27812 invoked from network); 22 Jun 2021 08:49:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jun 2021 08:49:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DCC9E180508 for ; Tue, 22 Jun 2021 02:07:58 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 22 Jun 2021 02:07:58 -0700 (PDT) Received: by mail-wm1-f41.google.com with SMTP id f16-20020a05600c1550b02901b00c1be4abso1231601wmg.2 for ; Tue, 22 Jun 2021 02:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=U5hNZKjTTcXhb7qolPOzfGOX5fqbk8y/tCKu2DE4hwM=; b=WlVuziROkDyzpoGh8GhZetk+tu1esaIIQYH04hePdmA4AD/OIF4bArTpk3xjramD0D pFXozyxU0L7C8C+BatxWBNiAn8jURprS8TUrPYGfK/jYNw8qindJZlSWhHgu9ZqO2p0y BrdhhItA/w//0mVpCVR7OjJtbpxrzKROeu/qYXTpYvOi4xxht9w7YjLeUqm6w/Y42Nwg aSxL8tzDPJLj30YEDMQZp8/KaSxaGI3gF4UQl0AsdM2/E5N9XkfuhlNbY6v8o+YIq5ps GQsrXE5eOV6NjJrT5J3TZHQkK1z1HgkEfHzjWAFdWtadIcEAVSvpdVdYGJxrM/LpiLU9 VMxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=U5hNZKjTTcXhb7qolPOzfGOX5fqbk8y/tCKu2DE4hwM=; b=cZLcWm/35GrBu7KB88nZiBOOqRnQD7o/TPejGz82oVfvC5X+AZYnLEGwatL3h75LTH 8BvuDYEGeEWvsz8tt3GzYcyIUJUCCo6zrQMMGh2f8mj7dLCeylZlsanxdCsvo64hjeQJ eky4dSq1tN5eGBVOFm4E+1NDUsxy7CQGIHQ7ny1Borej9dgnqLKoLxCz9AuzbWiBViXo Ine2AR1nSvCO5ik0UqxzIP1eHrBO7OKTJn2bCpwpCS0NsrZz/p54gSxgsdnrBd5+s4Eu /qGdYBW5rbftnsp5AJrDGhu+4VDYcJwTarcNj5Mze/k+5OSIigKpa7FWNAXKbnDQT+ij kDFA== X-Gm-Message-State: AOAM5312NR1Xzu2cQqtl3JgHXXLlHijUQjjkJCeBYldB6NJyVH1DnZUq SVmHscSA4myGPfdXDlM8opiWeVWnuMw= X-Google-Smtp-Source: ABdhPJyqt4QXpoLjBiFsvSD8aw4n9joh/a815tVi7ajQduyejq6Pnng0zzv4RHtRw88O4eCQd5lNzw== X-Received: by 2002:a05:600c:1988:: with SMTP id t8mr3206354wmq.23.1624352871660; Tue, 22 Jun 2021 02:07:51 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id x81sm2082219wmg.36.2021.06.22.02.07.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 02:07:51 -0700 (PDT) To: internals@lists.php.net References: <7f2da982-e29b-ccca-bddc-24ae7f4b0390@gmail.com> Message-ID: <9f0ca239-d022-1612-654e-9cd6cd60a939@gmail.com> Date: Tue, 22 Jun 2021 10:07:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] [PROPOSAL] Bare name array literals (again) From: rowan.collins@gmail.com (Rowan Tommins) On 22/06/2021 01:03, tyson andre wrote: > If linters and automatic fixers were set up for a project to enforce it (e.g. phpcbf), > there would only be one way that literals would be used in a project either way. The only way to be consistent across a whole project would be to never use the new syntax, since it can't be used for all arrays/keys. Otherwise, you'd have to encourage either mixing the styles within one array, or switching arrays back and forth if keys are added and removed which meet/don't meet the requirements. > Also, with no common interface between those anonymous classes, > using just anonymous classes would be writing functions that accept any object or return any object, > which would be error prone and hard to analyze. > > Those anonymous classes wouldn't have any ancestors in common for `instanceof` checks. Yes, the simplest anonymous class, with only untyped public properties, is equivalent to stdClass, which in turn is equivalent to a plain array. However, you can then add natively checked types, implement interfaces, extend base classes, use traits, and so on. And then you can switch to a named class with minimal impact on surrounding code. Unfortunately, a neat syntax like object(foo: $foo) loses most of those advantages; what we need is something that lets us keep the class body, but "capture" variables from the declaring scope somehow, e.g. $foo = new class(public bool success: true, public array data: $data, public CursorInterface cursor: $cursor) implements Bar { use BarTrait; } or $foo = new class implements Bar { public bool $success = true; public array $data = lexical $data; public CursorInterface $cursor = lexical $cursor; use BarTrait; } > Also, if there were optional parameters, that can be represented in non-standard JSDoc supported by static analyzers > (`success: bool, data?: array, cursor?: CursorInterface, errorMessage?: string`), > but that wouldn't be represented in an anonymous class > (setting a property to null is not the same as omitting it). Certainly, if what you have are dynamic keys rather than fixed properties, then a key-value array makes sense, and I'm not suggesting we remove that from the language. But I do think we should be adding richer choices beside arrays, rather than just more ways to write the same thing. Regards, -- Rowan Tommins [IMSoP]