Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113500 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53836 invoked from network); 13 Mar 2021 10:28:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Mar 2021 10:28:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4678A1804B8 for ; Sat, 13 Mar 2021 02:21:31 -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=-2.1 required=5.0 tests=BAYES_00,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-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 ; Sat, 13 Mar 2021 02:21:30 -0800 (PST) Received: by mail-wr1-f46.google.com with SMTP id l11so6133887wrp.7 for ; Sat, 13 Mar 2021 02:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=fGsLd1oo6Y9aoBApIfsL+Quz0rU81VeAJCK4sJNZVR0=; b=lBsEo5LsWDi4HMRwXpGIArJjtH/Q+VANASnsDGURTEF9ycTYVw7Qmdg9h024wEqqQo vYOxxAv+TDodTirfzIfEnCEK98jsoDvb8B3ey0lVbYsjRsHn5lP0l6Jr5VQ2iyGG3jy8 qzkX6VZStZGRbhUP74njGnR1gqyjaduGAzv432S9wIRmlWHPUcOMnF664Ax6GxrTdNtc 6lOah5NrX1gAGRU3w0yEV77VgT5GognOrh9q4v/nAm0vedk42k20U4+/gLzK9BU4Ga4D l7vo0+XslVRQTNAt84e5P+lL+bd4rGvBN3Gu/w9cLT9bNma2MH1TpbQhvjoFpaf5X6Rk 0Y5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=fGsLd1oo6Y9aoBApIfsL+Quz0rU81VeAJCK4sJNZVR0=; b=nmrIfdYrH57/yPfeEaxqeSTE7lzGv/zx/teaCdaNwOoZ3wPDrBUz6QBpmfGoHfPThM 6Bo+V1fRaDjXEyV7Z6n0fdZgdzvp3wsWdqTESqOMzVI3MPvkwaqxJYx+0eN4HKgEPIiC r5cZptBD2Tfx3VUyq3ISxITyydqNewg1PkRk8qJjkor55kz9OQ8gq1xj3qpcoOarTEQK bnG9iYuYWVqKPWYEjQNyZipFDcU5chCksaOrZMXgipTYCZbddVZkxF/NNY3HsqAVIvO/ YpqhULQh8AoeLlGlkkab2vZYBykDbwezV8FiW4FfQMbg5zSAPm2s8Rm0jEMZ/qlW+myv 47Qw== X-Gm-Message-State: AOAM533Edw7xIpG379XDguyvd9sxrRV3Qm3pIY0E1Oo5mHQ79v4cB6UL f2t6MQhPkgSCQ279pD/VKhr/EZACzo4= X-Google-Smtp-Source: ABdhPJyG0qPL84N+nBVd4f3xUmCES68AEPHnyUZmsS97YFOkF49m3Zj/IEoa8wEyqL/p+La9OG63Aw== X-Received: by 2002:adf:ce8a:: with SMTP id r10mr18323232wrn.17.1615630887084; Sat, 13 Mar 2021 02:21:27 -0800 (PST) Received: from [192.168.0.27] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.gmail.com with ESMTPSA id a13sm9806333wrp.31.2021.03.13.02.21.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Mar 2021 02:21:26 -0800 (PST) Date: Sat, 13 Mar 2021 10:21:27 +0000 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: <9C9FB480-6BAB-4318-8AC2-17A511A28866@gmail.com> Subject: Re: [PHP-DEV] Add support for ::class to constant() From: rowan.collins@gmail.com (Rowan Tommins) On 9 March 2021 22:15:49 GMT, "K=C3=A9vin Dunglas" wro= te: >Hi folks, > >Currently, it's not possible to use the ::class special constant with >the >constant() function=2E This doesn't work: > >var_dump( > constant('\DateTime::class') >); While this looks logical at first glance, I'm not sure this can actually w= ork, because you are asking at runtime for information which only exists at= compile time=2E This is similar to other "magic" constants such as __LINE_= _=2E The only cases where ::class is calculated at runtime are self::class, and= the recently added $obj::class, where $obj is an object instance=2E All ot= her uses are expanded by the compiler based on the namespace and use statem= ents in effect at that point in the code=2E If you try to calculate it at r= untime, it would end up being evaluated where the call to constant() happen= s, which wouldn't actually have those namespace and use directives in effec= t=2E Consider this example: namespace Acme\Foo { use Some\Other\Baz; function test(string $class) { echo constant($class =2E '::class'); } } namespace Acme\Different { use Acme\Bar\Baz as BarBaz; =20 echo Baz::class, PHP_EOL; echo BarBaz::class, PHP_EOL; echo test('Baz'); echo test('BarBaz'); } Logically, the calls to test() should result in the same output as the dir= ect use of "::class", but the call to constant() is in a different namespac= e, with different use statements=2E I'm not sure if use statements are even= available at runtime, but if they were, there would be no way of knowing t= hat the context of the call to test() should be used, not the context where= it's defined=2E Regards, Hi Kevin, --=20 Rowan Tommins [IMSoP]