Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120289 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86256 invoked from network); 15 May 2023 17:45:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 17:45:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 740D7180503 for ; Mon, 15 May 2023 10:45:01 -0700 (PDT) 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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 15 May 2023 10:45:00 -0700 (PDT) Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6ab38a85a1eso4507243a34.1 for ; Mon, 15 May 2023 10:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684172700; x=1686764700; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Z9VzFT25LM6J5maUwNSMZ1cXwPn5BQochh26KLafw0M=; b=IJ+b9bc18WQunw2RIwkFiEtCYgC1BszGGgF1/diKFKndP3ctGMliziA8GhM1xSpV/C pzUx/zyHnBUV9QIOFWclgi7HGeq+48NzGzGMje4Buz5MArrqR29t4uFZnUy9TW5h/73P Mr1gk+JTeBAVbOJzVyfjV9X74yVGuwxE/yJ0bQtRab6AsQSgcpZDJBUwD3YpNFMzyXoo wJ5Fic899MkRPEKPzYaOyQCbHdIQpfwWBeDlyOIgbumUjLlv4RlZ9/7Brs9DnJW4V1Qz 2gzzrU7g9OFbXKb7GFTji9T3V6KCK06pYUrZFU4Y6qQ6DP5xzw6JDYT9MeDWMcwCnctm xeOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684172700; x=1686764700; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z9VzFT25LM6J5maUwNSMZ1cXwPn5BQochh26KLafw0M=; b=QPiecvfg8G/zgIyF+L8uiXTq4UBDoCc4rdED77YbbHyXvHBeTicGqd1eOt5JgnCZeb 5xVHtbk5aLuWuhNZCk92KQTG1LcXbDxySpOQuj8yNu3OeNcRdlhPoMdzcjLgZGylfZfv 60xSs0UfD3VixLC1cFCl1zicO3Q7Lz1KWnAVRJfu7Rs9/Isplm8yxUAEZzlRsfHCxj9m 2PpGomW+pjoj89GNdYxA38BvqxqOAR8NLkFdpXsuOIBt+YRnQgLzRLe75m6K9jiJMB9Z 7y/GHOfrZrG63uGJFSeDNjD337++mfaQrsBDEe71ZzBIHdBfmYaeUemOSd3wTvpndyDf /nQQ== X-Gm-Message-State: AC+VfDzFWrjstIQs6ZGWPwChrWcbmLJfDy+jSSa/cm/tH38SLR6wlTxZ TCBC8MOsZwOIV1loUbeIdG2KBsOMcnbKVEh+dbKopPpktLtcag== X-Google-Smtp-Source: ACHHUZ6Ap+yfNMu3vHgpSXCg+U0ipb7Y2q/wrHHYcifZ2hoFvTCu1VdwYC4JpcrBq1X7nqETIIITaFK65CfiCT0XPdc= X-Received: by 2002:a9d:7f9a:0:b0:6ab:67c:c385 with SMTP id t26-20020a9d7f9a000000b006ab067cc385mr11280152otp.14.1684172700117; Mon, 15 May 2023 10:45:00 -0700 (PDT) MIME-Version: 1.0 References: <436378BB-FDFA-43BD-A633-C030C347E683@gmail.com> <359D9C64-52A5-4BF5-91B5-72F7CE116F78@gmail.com> In-Reply-To: Date: Mon, 15 May 2023 19:44:47 +0200 Message-ID: To: Lydia de Jongh Cc: PHP Developers Mailing List Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [Discussion] nameof From: landers.robert@gmail.com (Robert Landers) > I totally agree with Rowan. In many (most?) cases you need the fully > qualified name. > Even or especially for error handling! Of course mostly the error is > somewhere else. But you want to know the starting point. An > unqualified name gets you nowhere. Although backtrace can help you > out. > > And this is also consistent with how ::class or get_class() work.... > it gives fully qualified names. > On the other hand you could argue that 'nameof()' in itself means: > 'just looking for the direct/unqualified name of something' and is an > addition to ::class and get_class().... This is exactly what I was thinking when I wrote it out, however, you can pass the full name to get the full name (an escape hatch of sorts). > Then we still need something to get the fully qualified name/path of a > variable or php-item. > For a class we have: ::class, get_class() and class_exists(). > And inside these function you can use: > get_class(MyClass::class); Variables don't get stored in a namespace or they exist only in the local scope (they can't have a 'qualified' name, in my experience): namespace A { $b = 'c'; } echo $b; // outputs: 'c' For callables, you can already get the fully qualified name: echo (new ReflectionFunction(strstr(...)))->getName(); You, however, cannot get the name of a constant, except through get_defined_constants() and comparing values (searching in the namespace you care about) and doesn't help you if it isn't defined. There's further evidence that an unqualified name is the right way to go: use const \NoExist\TEST; use \NoExist\Channel; echo TEST; echo Channel::class; the output is: Undefined constant "TEST" in ... Channel note that it does NOT say "\MyNamespace\TEST" is undefined nor does it output "\NoExist\Channel", so if the user wants to write: use function \AppPlugins\Config; if(!function_exists(nameof(Config(...)))) throw new Exception(nameof(Config(...)) . ' does not exist, please define it.'); It's going to output the unqualified name anyway, simply due to how PHP resolves names. Using the "escape hatch", however, we can "force" PHP to do what we expect: if(!function_exists(nameof(\AppPlugins\Config(...))) throw new Exception(nameof(Config(...)) . ' does not exist, please define it.'); I'll update the RFC to reflect this. > The downside is that we get many new 'magic constants'... There are no magic constants in this RFC. Robert Landers Software Engineer Utrecht NL