Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112862 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53606 invoked from network); 13 Jan 2021 10:01:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jan 2021 10:01:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD6C81804F2 for ; Wed, 13 Jan 2021 01:39:13 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 ; Wed, 13 Jan 2021 01:39:13 -0800 (PST) Received: by mail-yb1-f172.google.com with SMTP id z1so1577655ybr.4 for ; Wed, 13 Jan 2021 01:39:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=2s8PdNNwsXSwHILYrSYdYWr6RhjVGBC2vYL7M5zZuzQ=; b=I/AFrgnxg8+lZLB78Xn0WI0kFSCNVFKpVyG6c3nuyJA340i9eBIKMj/mlBGDJgcvqU fph5mbKmIMmeiN0RgR1ljcZjhoXSQ0/ge2wGHAOLc8iMpCeV+HTeXxd4xPu9sQtNUlXx IX6Xnv7jO+LihHFHwsexLzlwW8aDbiVY+JNrD9RAjpESkUkLh7OAQaJfiEgO2QvEHLXm dNf0uxOK7BsxJq75+Y4wbzB09GPyl+/kdecEc69mq+0qqsiEKimsSu4I7gqZLt1x3R4H tD1yt+XaGtRPKIv+AHDEXlpxS4iVZUhVkABHEMXYDqjTZPKiJ8TQGtplsve3t9rD5PtY utXQ== 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; bh=2s8PdNNwsXSwHILYrSYdYWr6RhjVGBC2vYL7M5zZuzQ=; b=AC3yi+RBx4DCWfRt95RcogSDxlFfOsWXTDsjAd2Uh5OU1ZwfKTBIVcL4v+nV0BMX6E LHvgKcdWTYSmCgWwaAbL5O2E5USwMczGQAuZWsd6Y4jBtbmEOZM+Z2opeAY0tNho1bWW qLNFcafxeQMPK6pN3CVcitKX5IyRpd3gET01f8AKQxHh8nKRkR+IkaaxIM1Lm2DF6ocy sdE/hHa6wir4SghKjvdJiFQ+RY03GSeRUZdYJysdUvnyep/wKOZ86PaMjl415sGrjxXC xd7CdiBZ7Hpy2+YQzGDpQb1WEpIobuWk6c2fWVzOTwq3dRLIs0pConUfoMcV5oBsch50 +Zyg== X-Gm-Message-State: AOAM531N4YSJ9Lo9aHGZj07326LOG2P75BTDpihNMKIsWdeggFVH+pPr OUvzY3sFqIdZKQbXKczLJVNGcctI11o8iFazyPi9ww4bEkLRfw== X-Google-Smtp-Source: ABdhPJx/2iBImZkupg6fkXY7VmY1oZNA37v8vnneIhUovOE8+lDbLEN7TDcS2TI8lamX53UlcdbAOKKyQa9y6BaFw3g= X-Received: by 2002:a25:ab11:: with SMTP id u17mr2118453ybi.114.1610530746723; Wed, 13 Jan 2021 01:39:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 13 Jan 2021 10:38:55 +0100 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Allow object keys in arrays From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Matthew On Wed, Jan 13, 2021 at 7:15 AM Matthew Brown wrote: > > This proposal is interesting, and I see why the enum proposal makes it > useful. > > Supporting this will mean a small amount of work for me (assuming it > passes) and other static analysis tools, but I don't want that to factor > into anyone's decision. > > I am curious, though, whether the scope of this RFC could be narrowed to > just allowing enum cases as keys? That might avoid issues with objects that > cannot be cast to string. The enum RFC currently does not propose auto-implementing __toString() and actually forbids implementing __toString() manually in case we want to add some type of coercion at some point. While we could change that, I do think it introduces some inconsistencies. enum Foo: string { case Bar = 'bar'; } var_dump(Foo::Bar . 'baz'); // barbaz enum Foo: int { case Bar = 1; } var_dump(Foo::Bar + 2); // Type error // Will require Foo::Bar->value to work We intentionally removed auto-coercion from enums because the rules are complicated and not clear-cut, and type strictness is what the language generally seems to be striving towards. That is not to say narrowing object keys to enums is a bad idea. I think that might be worth considering for other reasons. Ilija