Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115620 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5891 invoked from network); 1 Aug 2021 15:31:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Aug 2021 15:31:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 40B9F180088 for ; Sun, 1 Aug 2021 08:59:44 -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.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS 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-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 ; Sun, 1 Aug 2021 08:59:43 -0700 (PDT) Received: by mail-lf1-f50.google.com with SMTP id m13so29001194lfg.13 for ; Sun, 01 Aug 2021 08:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=m8T5kZ+99GXAyq48yDTNvcjJwDTxBSkBoecBWZ/M1GM=; b=qxpZM7t1kdOjR2lcF3c89Q1g3O0Ezmuk+txlazszgUIHddKQqCM6eTb5pgxpij2oOY LuHX7HC5ilX917f6c1GU5EuBWXvM6Z/WwO/CLyOxH19s/S5PcEC2XF7HDzCKHmSR50lR WvbkUJ2kSBJOewiUundEpvlqoKHwNJXLoKSG77PTWVmFV9o1KB8os+54qDpYU2k95aOC VKIBmDUIOhQBnG6rX8m4DfgtreTYSxCG3g6tLzED3NIU/U84xZqfIGIuhX+THeXb2wN4 TQQBWfyU7ntSi9ccU7xIOhe8Gw1bMwO/snjbVc+KabhnITzrKv4cWd8hV9rPBbpnVp3C +QIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=m8T5kZ+99GXAyq48yDTNvcjJwDTxBSkBoecBWZ/M1GM=; b=V8g0n9aQtvoEvhmCua7vv4aZ8Z0xxjXwJj3cEBzWkwsz5XdLYYPqxWNJIHnN4ncrcE 0Qqd+1wvgdvnDnUCA+K7tNM3Fqk0wo4Hw/JD+IY5LTjsqNYo6Q962qWuF6iXWNlbsfAu JRakfrjA/+RNKHrCCB1C5wdNS7AUrzFjZeM1ifp45XTzYINlwYtgwQolaZwNXVvCO0fY urobkOhmLoNkoEAvAQp0qbdQzz1P3zQvEt/rLOzfhEefy/7cFI5qAfiNehi6zGNPOq9p B7JR6hNhWPXNRtasQEaAviHavVZsoqsbE3HEt0/YxEpWv5Cs96s/efbe7zRrDwm+3h5a y6eQ== X-Gm-Message-State: AOAM530NRmidO54VglkK7a81n+KPmdvalOsPIimET5YQbpdrlNLWJOgT T71BRCkieVy4/xVeZbWLGLQ= X-Google-Smtp-Source: ABdhPJzyf/elCD/ygWwj43JiDB2Id13plWd3oIHLiSzZ/GNe+jn5yG+efiKfpArn+fsQu9tpGqVHxQ== X-Received: by 2002:ac2:50c2:: with SMTP id h2mr2390611lfm.332.1627833581156; Sun, 01 Aug 2021 08:59:41 -0700 (PDT) Received: from smtpclient.apple ([195.3.159.227]) by smtp.gmail.com with ESMTPSA id b21sm701396lfb.169.2021.08.01.08.59.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Aug 2021 08:59:40 -0700 (PDT) Message-ID: <7FAE3AE2-F8C1-4774-9B84-721DE8FF49D4@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_7868AD87-5A39-409F-A783-98B6BE8B6794" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Date: Sun, 1 Aug 2021 18:59:39 +0300 In-Reply-To: <6e668a49-d69c-7b6d-f9c4-1d3fe2058d27@gmail.com> Cc: internals@lists.php.net To: Rowan Tommins References: <22EF92EC-C5A3-498E-9EFD-DE2B5B204BB7@gmail.com> <6e668a49-d69c-7b6d-f9c4-1d3fe2058d27@gmail.com> X-Mailer: Apple Mail (2.3654.120.0.1.13) Subject: Re: [PHP-DEV] RFC: autoconst From: free.smilesrg@gmail.com (Serhii Smirnov) --Apple-Mail=_7868AD87-5A39-409F-A783-98B6BE8B6794 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 1 =D0=B0=D0=B2=D0=B3. 2021 =D0=B3., =D0=B2 17:08, Rowan Tommins = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0= ): >=20 > On 01/08/2021 12:21, Serhii Smirnov wrote: >> instead of defining constants like: >> const FOO =3D 'FOO'; >>=20 >> they could be defined like: >> autoconst FOO; // defines a constant FOO with the value 'FOO' >=20 >=20 > While I've certainly seen constants like this in the past, I think = they mostly fall into two categories: >=20 > A) Constants where the value doesn't actually matter, and you just = need something to compare input against. As of PHP 8.1, we will have = enums, where you can just write "case FOO;" and not assign any value at = all, which can probably be used in most of these situations. >=20 > B) Constants where the value matters, but the constant name isn't = actually conveying anything. Given your suggestion of built-in = transforms for lower-case etc, these seem like what you're interested = in. >=20 > These often arise from a misunderstanding of the dogma to "avoid magic = numbers and hard-coded values", and result in code that looks like it's = SHOUTING without conveying any extra information. For instance, people = start with this: I was more interested in autoconst keyword that reduces copy/pasting = constant name as it's value. camelcase and snakecase is an addition. A = real example why I wanted to use autoconst: on the past project, we had = class that holds constants with the feature flag names. Something like: class Features { const FEATURE_FLAG_WITH_SOME_LONG_NAME =3D = 'feature_flag_with_some_long_name'; const FEATURE_SOME_ANOTHER_COOL_FEATURE =3D = 'feature_some_another_cool_feature'; } later, in the code we had to check if certain feature is enabled in the = system: if = ($featureManager->isEnabled(Features::FEATURE_FLAG_WITH_SOME_LONG_NAME)) = { // some feature related code goes here } The class Features could be written as: class Features { autoconst lower FEATURE_FLAG_WITH_SOME_LONG_NAME, = FEATURE_SOME_ANOTHER_COOL_FEATURE; } --Apple-Mail=_7868AD87-5A39-409F-A783-98B6BE8B6794--