Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120173 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94318 invoked from network); 1 May 2023 19:00:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 May 2023 19:00:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 745E4180543 for ; Mon, 1 May 2023 12:00:17 -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=-0.2 required=5.0 tests=BAYES_20,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-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (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, 1 May 2023 12:00:17 -0700 (PDT) Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-187ec6a5504so2301801fac.2 for ; Mon, 01 May 2023 12:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682967616; x=1685559616; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=dKo8bnfOhxdHVFGNboO7+q1b6jnT21jYAUaqak9i1eM=; b=UHTYAfz60REhqIX4EP7BTbozFZ4BEKOEJ3h2vrx55FalWG7+nUUz+xw2avwMghoI/b bOg33bc3Bm0PuCW//V+jT8YWuc+wKPZUtBsL7Cw4StH6ueYoxKZu4PGAP6FHPBkLExF9 6rDG9pPS/mPJ10GGq8bxDk31U1qnZ5vmLlzD2AqdnG45TbFTq4QOyLkYfcSVnd9J1o6O wrf7igTQcl77fyPmjbgy9v8L0rNTh5fQ0JDZxx1TByNZbrDgdMAGNpVnse9zEzUzVKry KoYl7koq7Co7YwFVpWxdh8DoNeLib/rXzqyzVvvcNHbB+M7tKLmZtt8XuTuMEKbzFwUa RNzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682967616; x=1685559616; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dKo8bnfOhxdHVFGNboO7+q1b6jnT21jYAUaqak9i1eM=; b=QCjK9Hb6LCY5WF+rDqZqnW+NGQJfn52cvWpuAPrx3MH0eGMpNeGE+oqFdi/ll/2AjZ jHVT36qHltzXZadbSZaWmIpHUZ4F0IvXX4UkuTdzG7cOezoJK7kFSRDMTwpBOw5mFXJE yW6X7f6CcQ977UyvvmkLtvAy5tNVJfnkbrjOHgDkzeevroC5CbJCkUBK7XrpRlz5Z1Ha TosissQbC2cQCrYR8/OHra8p6LYtWihiQ6vjHrQL6WPV/WAjgxaRvBuFA2s0br/buN34 8GjKjvHW5vipgss2LeSYLxThcdBNDMJvYzAdH6Pjt5iqS/c4UNUXXTg0FPgMf7JDkmQv vzgA== X-Gm-Message-State: AC+VfDyPh6jexaooRjuhrqhwTBaws1LWKhcPZRchAisM99VhtuoJtJ0i pBV59Tiao8iw3uIU06mEwmhJ5hWqRBSRdriNLKWzE4d9/I+XlA== X-Google-Smtp-Source: ACHHUZ5Ak6sGJYQSifOIMcHIZmD8dF9gW4UK6/vTvgCeWZXMXtRQcVryIRprBlibDAhKa091Z6jxjAsOhrusoTJqAV4= X-Received: by 2002:a05:6870:9202:b0:18e:af01:ad93 with SMTP id e2-20020a056870920200b0018eaf01ad93mr6822540oaf.58.1682967615927; Mon, 01 May 2023 12:00:15 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 1 May 2023 21:00:04 +0200 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Subject: Pre-RFC discussion: nameof From: landers.robert@gmail.com (Robert Landers) Hello internals, After seeing some discussions about using enum values as keys, I thought of my own implementation of `nameof` (from C#) that is very hackish: https://github.com/withinboredom/nameof I'd like to propose making it a real thing (with better behavior than my hack). An operator like this has a few niche uses, mostly for better error messages but also for making strings of things that you normally can't get the string value of. Here are some examples: nameof(func(...)) === 'func' nameof($party) === 'party' nameof($captain->planet) === 'planet' nameof(Class::Prop) === 'Prop' I first attempted this as an extension, but this belongs at the parsing/compiling level and not during runtime (this gets turned into a constant zval). I use my (very hacky) implementation to handle stringifying enums (mostly), as well as better, easier-to-refactor error messages: throw new InvalidArgumentException(nameof($var) . ' has an unexpected value'); Without it, the name of the variable can be missed in a refactor, making the error message useless or incorrect. The code to make this possible (without much error checking) is relatively simple: https://github.com/php/php-src/pull/11172 Robert Landers Software Engineer Utrecht NL