Re: [RFC] [Discussion] nameof

From: Date: Mon, 15 May 2023 18:26:09 +0000
Subject: Re: [RFC] [Discussion] nameof
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-120293@lists.php.net to get a copy of this message
On Mon, May 15, 2023 at 8:18 PM Rowan Tommins <rowan.collins@gmail.com> wrote: > > On 15 May 2023 18:44:47 BST, Robert Landers <landers.robert@gmail.com> wrote: > >use const \NoExist\TEST; > >use \NoExist\Channel; > >echo TEST; > >echo Channel::class; > > > >the output is: > > > >Undefined constant "TEST" in ... > >Channel > > I'm not sure how you got that; according to > https://3v4l.org/gltKN only PHP 5.6 has a message with the > unqualified name: > > > Notice: Use of undefined constant TEST - assumed 'TEST' in /in/gltKN on line 5 > > Before that, there was no "use const", and in every version after that, it's a > fatal error with the fully qualified name: > > > Fatal error: Uncaught Error: Undefined constant "NoExist\TEST" in /in/gltKN:5 > > Take the constant part away so that the next line runs, and > https://3v4l.org/q0XQO shows the fully qualified name right back up > PHP 5.5, because expanding the name is actually the *only* thing that ::class does in that context. > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > php --version PHP 8.2.6 (cli) (built: May 12 2023 06:24:00) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.6, Copyright (c) Zend Technologies with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans php -a Interactive shell php > use \NoExists\Channel; php > echo Channel::class; Channel Turns out, it's a CLI specific thing, when running in a file, it does indeed output the full name. I stand corrected; I tend to use the CLI for testing out stuff.

« previous php.internals (#120293) next »