Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108082 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65511 invoked from network); 10 Jan 2020 00:24:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jan 2020 00:24:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B995C1804F4 for ; Thu, 9 Jan 2020 14:30:26 -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.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) (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 14:30:26 -0800 (PST) Received: by mail-pj1-f65.google.com with SMTP id r67so108424pjb.0 for ; Thu, 09 Jan 2020 14:30:26 -0800 (PST) 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:content-transfer-encoding; bh=F70N2LSxvymsxhBOaNsvf3b+d3N5dzQsca679jjsVRY=; b=SOCR9446FhJVDjg372BN6bpoWtRKD0km7samfYdQH/vZMfrDgDOXduPx+8+1tjduak wf6xFVb9meIasYOtUmPsYVUEmH1y8WXn8i7A3A/JQmJVxYPq621tUAMSH+xCLGaUV1Zf bCpazsZByF1Nni9uy4dQ59bGKk3oQXgnlf8nQy07V8eytri5vOQlsJ6Uqdt/KVCqUZAF 932WPvExbt0fvIL+b8i2g6GMxh4lYXBrp3GsypdJGcNv0O2OlDO2aZ2W3nLDRcVfGQAv cSD8WB1YjHDUaKsOnK+Ao6LhHkgJnUNKElXpTE2POr4LbQ3/NPgYBLZi06rKGorpOWUk KfUw== X-Gm-Message-State: APjAAAVusgUe44UGeuqUmXUZEzOyK5te3qiyKMhcQwYVL1wBHpFaXbgc HnxIhpRD/da4t0WILCNCLDHBGVOmes9P54uJ91I= X-Google-Smtp-Source: APXvYqzZR66MSS3rZEPPhCYzTZsuVFHjdBYsN5oGEXI4oGZFEoqc2CEnTgp8FxHj9Jz6I5EisNE7HwOR59VSz1wSv3Q= X-Received: by 2002:a17:90a:d141:: with SMTP id t1mr499933pjw.38.1578609022988; Thu, 09 Jan 2020 14:30:22 -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: <032B5597-6CB6-4F5E-BDDC-8A508C3FCE93@newclarity.net> Date: Fri, 10 Jan 2020 00:30:11 +0200 Message-ID: To: Mike Schinkel Cc: Ralph Schindler , Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Allow ::class on objects From: kalle@php.net (Kalle Sommer Nielsen) Den tor. 9. jan. 2020 kl. 23.30 skrev Mike Schinkel : > > > Den tor. 9. jan. 2020 kl. 22.41 skrev Mike Schinkel : > > > > Traits are compiler assisted code copy/paste and not contracts (unlike > > interfaces), so there is no gain in having ::trait. > > It can already be referring to using ::class so it makes little sense to = disallow ::trait unless there is a different reason not to add another ::ke= yword. It is not about adding a new keyword; the keyword "trait" already exists and "::trait" is a combination of an operator and an already existing keyword (since we are educating each other). I cannot see any benefits to adding the ::trait syntax (nor the ::interface) one besides some OCD issue that you are using ::class on an instance or name of something that technically is not a class, like in your below example, even less when ::class already is working. > Traits are symbols, so it is not unreasonable that there would be a way t= o access it symbolically so that the reference can be type checked. That is where you are wrong, traits are not contracts, so therefore they are not types. You cannot check that a class reuses a trait or not when it is constructed because it is compiler assisted copy/paste. They are a useless symbol to refer to in the context of ::class. I can understand you wish to make a helpful error message to a developer who fails to write a class that is loadable by your runtime, but in your example you are still refering to the trait as it was a type, which it technically isn't. > > One of my use-cases for referring to traits is to provide helpful hints i= n error messages, i.e.: > > printf( '%s does not implement %s. You can easily implement that interfac= e by using %s', > get_class( $this ), > Interfaces\Foo::interface, > Traits\Foo::trait, > ); > > But the instanceof operator does not fulfill my requirements. I manage e= rror triggering during development and logging during production within the= function. Thus I can just use the implements_interface() function to handl= e errors automatically when I am testing an assertion vs. using it just for= branching. > > You'll note I explicitly included a third parameter `$trigger_error =3D t= rue` in hopes people would notice, realize what I was doing and not think t= hat I needed to be educated on the existence of instanceof. That is fine if the instanceof operator does not do it for you, but you could have left that last part of the comment out of the mail, after all, it was just a tip. --=20 regards, Kalle Sommer Nielsen kalle@php.net