Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108080 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56980 invoked from network); 9 Jan 2020 23:24:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 23:24:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B83D0180532 for ; Thu, 9 Jan 2020 13:30:12 -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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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-yw1-f53.google.com (mail-yw1-f53.google.com [209.85.161.53]) (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 13:30:12 -0800 (PST) Received: by mail-yw1-f53.google.com with SMTP id 10so3305496ywv.5 for ; Thu, 09 Jan 2020 13:30:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OdjmuIUwZS4A151qKtN6Av9sokzsS6k2P+BgFhI0Uvw=; b=RXEXe+CAQ1yq9GWkFrbIvClvJOG+1vDXa+Mea2ePEpyN1cZbJXLt3Mk4U99p4c0qi2 fGKoCJoPdMjj61y7A1JbpsGOE/i8Em6LPNtgH9lGUXFPE4eBEByt4IympllWqwDJ7oKO T1KnU7svXOhyPJ7OEuOO3y5PjsD+lyhya2u8N87r+e2/Nx/yh+ktJurkhUdiFwGKNiyL HUyfXb2+Cl5oV/cfob8FVEoRpSFhbJx/H6YKbm+XMGz4W4cLpfu+jqCUCp+LfiHEjjTa NJkR8Q+V9ypALmhhUN5qyEduVoad/7QEggzH/zYc017is7IZSdSOU4S805z5ywsfMuxw E/iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OdjmuIUwZS4A151qKtN6Av9sokzsS6k2P+BgFhI0Uvw=; b=LOC5y4+hSa5iIVRIviaGPzUHAEXmWSjzRhKQkWmIWeV/iInt4f5WStXSpgKjdfhDUf rum6QWPeHxvB5AlySvsg0+vtXNYgYH2CIkz4JXZKLClzzd1Ijj9ekOKRfH2y/9HKv0jX xsGPzafTmXPrMFI8CO9wRxiA22wfFdvR/zFlRsaofdNHohXPbtjbYvNfqQDBU6F0Ecpz RSzT+kvxeTdhKJC+sODYZgda/lFMxt1QHDLW23Os+zepk3OeAfviEHm4MgXmVtt37SQp B65a2nbPf0IOE2UH1ve8RgeHhoEkWg5AkxTXNABtZSr6MqGhrYMJaCUdSrqGP+gJgVUq DMvg== X-Gm-Message-State: APjAAAX81TKASI1uZIKuV6Ht/a+4j0DnjjwG8Ah3gTpXYcH3SQVft69w PFz/vowcsOhRS0URC+2ReYRJfg== X-Google-Smtp-Source: APXvYqyk7mf4RPS+K1/0EFFLFM9sIJSJJx/Dmr+5EJNbkNqHwg3sWkuaIiqSZYgmXwbyZ7XpPB+OuA== X-Received: by 2002:a81:2e01:: with SMTP id u1mr105592ywu.512.1578605410054; Thu, 09 Jan 2020 13:30:10 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:480:e2c0:f7b2:a682? ([2601:c0:c680:5cc0:480:e2c0:f7b2:a682]) by smtp.gmail.com with ESMTPSA id r10sm13818ywr.97.2020.01.09.13.30.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jan 2020 13:30:09 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Thu, 9 Jan 2020 16:30:08 -0500 Cc: Ralph Schindler , Internals Content-Transfer-Encoding: quoted-printable Message-ID: <032B5597-6CB6-4F5E-BDDC-8A508C3FCE93@newclarity.net> References: <13CC52AA-7690-42C6-89B7-B8FA4166BF38@newclarity.net> <57c08851-e6e2-c0bd-76e1-f7a0388d64b4@ralphschindler.com> <60610660-2E38-47BD-A998-1E226CEB3701@newclarity.net> To: Kalle Sommer Nielsen X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] Allow ::class on objects From: mike@newclarity.net (Mike Schinkel) > Den tor. 9. jan. 2020 kl. 22.41 skrev Mike Schinkel = : >=20 > 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 = ::keyword. Traits are symbols, so it is not unreasonable that there would be a way = to access it symbolically so that the reference can be type checked. One of my use-cases for referring to traits is to provide helpful hints = in error messages, i.e.:=20 printf( '%s does not implement %s. You can easily implement that = interface by using %s', get_class( $this ), Interfaces\Foo::interface, Traits\Foo::trait, ); >> use Interfaces; >> if ( implements_interface( $object, = Interfaces\MyInterface::interface, $trigger_error =3D true )) { >> return; >> } > If your $object variable is an actual instance, you can use the > instanceof operator, it treats the right operand as a first class > citizen and allows you to skip writing ::class: But the instanceof operator does not fulfill my requirements. I manage = error triggering during development and logging during production within = the function. Thus I can just use the implements_interface() function to = handle 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 = true` in hopes people would notice, realize what I was doing and not = think that I needed to be educated on the existence of instanceof.=20 -Mike=