Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108085 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77598 invoked from network); 10 Jan 2020 01:47:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jan 2020 01:47:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD6D61804AC for ; Thu, 9 Jan 2020 15:53:37 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, 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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 ; Thu, 9 Jan 2020 15:53:37 -0800 (PST) Received: by mail-ed1-f44.google.com with SMTP id c26so7153240eds.8 for ; Thu, 09 Jan 2020 15:53:37 -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 :cc; bh=AuugoBs68kWF+3nma98KhgfDnA1uQ7k9jUCbWPAfL9c=; b=ds8nni+M/v7Ov4zbAB25fizVIiZHb7EN09g8ELhnHatp5CJ1N7L9BH+0GPJGNG4xSw laxlMSl9R+Okt9nSmo1hI6+MOHBd+fDXGLkBTMpbPZTzO9QdBqBFSFjXhhmNmVr1etXn EHIScilT4GwX4Ex6HcFQGRIIBOCNC/+QsuHwK1eX/mmYp86s9WqzxYJNYzenU6IOF3AS i+rkoGAbFK4Jowh+5iW+QeV/y45Hdbjjt23lMWurIqNgVUcNSmAGrY6ekGZwozELEImP ZBO9hpnEFpcMXu9CWM3Wz+h42mC6UqUuREau/v4L+rtruTWu86dKD9b0yE1BuzqyDcrT ck3g== 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=AuugoBs68kWF+3nma98KhgfDnA1uQ7k9jUCbWPAfL9c=; b=b6WlH/BNGhP5Mx/qiRZh3tAtM/lgdwWHEhmc4d2d6NuwE8dIvwKuOitIuhIMaC36nW 3TBtvsRLvVYxB6LBbGhyWaWoMG63CUmeMBMPW8TJ70hpUNiFA9bf7sps7cT8lsbHupnm iThtySve6JhPSfpxW02RYWFTIOE0G6m5E6Wa1tXTbEMOMDwrR2oe7APeiDSisV3yOEUV dJMFuHGzSXjqynIqHeu+DslXWPcQIscwakhdHC+hJ3kCxck6f+ujJFO9L6JL04cPKxdH 9Cpl2tb6/MeqkSEB5QMVTk83moo4cTTevlnR3HOKjCV76FccqA84o32F6UtL+05OmOQs W+8A== X-Gm-Message-State: APjAAAVY0vqY7qgYAVUPQeb1fw68EI54tYP7fuO/Z7lcOVfbAxNygsqu 8JQqqmZ6ipH5eysfuQfrNt+94DkEpqpoLwXsI0cW4ihoyac= X-Google-Smtp-Source: APXvYqyb/qF7eB5rMA48x9ulxuLh+W7Gsu54F1YJf/fJYijHygIf/c+Od/zS5AoFG+KohZjZICa92i540U2ZofsAPVU= X-Received: by 2002:aa7:cf83:: with SMTP id z3mr407393edx.166.1578614015122; Thu, 09 Jan 2020 15:53:35 -0800 (PST) MIME-Version: 1.0 References: <13CC52AA-7690-42C6-89B7-B8FA4166BF38@newclarity.net> <57c08851-e6e2-c0bd-76e1-f7a0388d64b4@ralphschindler.com> <60610660-2E38-47BD-A998-1E226CEB3701@newclarity.net> <032B5597-6CB6-4F5E-BDDC-8A508C3FCE93@newclarity.net> In-Reply-To: Date: Thu, 9 Jan 2020 20:53:23 -0300 Message-ID: To: Mike Schinkel Cc: Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Allow ::class on objects From: marcio.web2@gmail.com (Marcio Almada) > > Hey Marco, > > > On Jan 9, 2020, at 5:04 PM, Marcio Almada wrote: > > > > Regarding the inclusion of new keywords with similar behavior of `:class`: > > > > Would `Interfaces\FooInterface::trait` or `Traits\FooTrait::interface` > > cause a run time error? If I'm not mistaken `::class` can't trigger > > error because it can't trigger autoload like `class_exists()` calls > > does. > > > > Currently `::class` can be used to resolve any name like > > `trim::class`. IMMO it would be weird to have `::class` with the > > current no autoload / error free behavior and then `::trait`, > > `::function` and `::interface` triggering autoload and emitting some > > error level. > > You are absolutely correct. I am so used to PhpStorm highlighting issues that I sometimes assume that PHP will throw an error/warning for the same. > > So if ::interface and ::trait were added, then (tools like) PhpStorm could have enough information to flag them if developers misspell them or they are otherwise unknown. > > > And also it would be weird to have `::trait`, `::function` and > > `::interface` with the same loose behavior as `::class` > > Why weird? > Because we would be expanding a construct that already looks inappropriate from a purely semantic POV with aliases that also would allow inappropriate usage `some_function::interface`. I'd rather have a generally unsatisfying construct than a set of "denormalized" constructs with equal potential for human inaccuracy. Perhaps the problem is that `::class` was not exactly a good language design decision in the first place or maybe it made more sense in the past and as the language evolved it started to appear to be named poorly. A more _general_ construct like a `nameof` operator, as we have in C#, could have been a brighter idea. See: - https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof - https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#nameof-expressions > I can only assume Foo::trait vs. Bar::interface vs. Baz::class would not be hard to grok, and that it would would provide more valuable information to a reader than Foo::class vs. Bar:: class vs. Baz::class. > > > in that case, it seems less surprising to have just `::class` > > everywhere instead. > > How so? I was very surprised when I first realized that I could do MyInterface::class, but I would not have been surprised by MyInterface::interface. > Others could say they get more astounded with `SomeTrait::function` being equally valid. It's much easier to explain that `::class` is general and works everywhere (even though I don't think it's good). > > `::function` > > That said you bring up one I did not but would also like ::function as well as `::method` and even ::var or ::variable and ::const or ::constant. > Hahaha You're welcome :P Marcio