Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108016 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99126 invoked from network); 7 Jan 2020 00:47:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Jan 2020 00:47:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D922A1804D1 for ; Mon, 6 Jan 2020 14:52:44 -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,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-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 ; Mon, 6 Jan 2020 14:52:44 -0800 (PST) Received: by mail-wm1-f49.google.com with SMTP id u2so17237318wmc.3 for ; Mon, 06 Jan 2020 14:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=5GeLmFuYuwBewL07BhnoKflCKK35xxJjc18SkLJu8qI=; b=dl0uhkzOPQfdQ1Lx4ISxV0+Hth/LBzEOXy400Onqs+u6DcEL20cBZ76REgSHeeg+SH EEDORN3wgjcOoj7PbIO5sJMv6olWQuf5XTo3Cy8QJpNUmxHPySTyJo469RN0g+xMJeKi zsOo670W2sZ+hGJtS9oB/hB/N2eEBJPxV/6YN6FLQEmKbVkCALNV0kkZJH+U/jK9W2ze mEX6y8hLv7qcakaEbhj/kEGXB/Hr+Mgsy6LOUblgvbzcwjBgq9u+X1Tko0zkERxkky34 myM1mmbzAdamLFxnlmauosDhItlDyFbNvuS2GZM93pObGup17vUsTk6cloLF6w/q3FuX WRgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=5GeLmFuYuwBewL07BhnoKflCKK35xxJjc18SkLJu8qI=; b=Aw5lJfKxsq/n6PcBTcITGHbV6N/S5jD++OnyG/ElgZ2GKM0Bscdko9yiuFroodcapW YSmzGRx5PXUNoZKmAq6JhGl0tLA/PTIxQ/d+u1ZKLIRVEvMBXRqeLlw8DgAtGA2MJXRy MhqPJi7QiEDSoR/h0upX+4zqN+Qvl4FT6rDjZEgUoLKefPWj5W5kRHpL0xva6k7HiWKK 5gmwQbpyLYo3MhfUAr9D7CRjGGso78m830BjXY4hn+k+WB7Jg7wmYVh8U5i62ZW+YS+l RJd3jbVQRk6lYilhgfhO3ylcj/jSDyLGslu61MEW45gkFwgZbqwUNYb1sGNjGXItDhFT BY8w== X-Gm-Message-State: APjAAAW88c7iIYRF5EioNoroXI3E4bo8cEFaF+AJrkI1zUaE+ztd8xqE sVQ4pnxCt3SAadIJHPYU+ywF+WZM X-Google-Smtp-Source: APXvYqze2PtDZGvRCyU/fwqPBkHxAJeOBWNKO+AQ+L16bVGZMt3zWX2hxvDZ66ZK9dH8MmtFxQVxXg== X-Received: by 2002:a1c:4b09:: with SMTP id y9mr37645021wma.103.1578351162040; Mon, 06 Jan 2020 14:52:42 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id k11sm23860451wmc.20.2020.01.06.14.52.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Jan 2020 14:52:41 -0800 (PST) To: internals@lists.php.net References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> <8D8F3E7E-137E-459B-B13A-9C7940731243@newclarity.net> Message-ID: Date: Mon, 6 Jan 2020 22:52:38 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <8D8F3E7E-137E-459B-B13A-9C7940731243@newclarity.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Initializing constants once, with code? From: rowan.collins@gmail.com (Rowan Tommins) On 06/01/2020 21:01, Mike Schinkel wrote: >> On Jan 6, 2020, at 5:56 AM, Robert Hickman wrote: >> >> Would it be worth expanding the ideas of programmatic constant >> definition into a more general compile-time code execution approach? > That would certainly be interesting. I do not know enough what is possible there to opine. > > It it were possible that might be the best of all worlds. > > Anyone with experience in that area able to comment? Isn't that the same as pre-processors, which elicited this response when I mentioned them before: > Oh God no!  Pre-processors are definitely an anti-pattern, in my book. >  I came to that conclusion sometime in the 80's and have yet to see > anything that changed my mind. Perhaps the phrase "pre-processor" put you too much in mind of C / M4 style text macros? If so, that's not what I meant at all; what I meant was some tool that evaluated some syntax during a "build" step, producing valid PHP code. That might be as simple as string substitution, but it might be special code blocks running standard PHP, but run as a separate build step and the results inline into the code. It could be as general as this: namespace MACROS {     function getenv($var) {         return $_ENV[$var];     } } class API {     const URL=MACRO\getenv('API_URL'); } Parse the code to an AST, allowing function calls with literal arguments wherever a literal value would normally be allowed. Find all function calls to something in the MACRO namespace, evaluate them, and substitute the result into the AST. Then write the modified AST to a new PHP file, and deploy that to your server. Obviously easier said than done, but there are tools out there like https://preprocess.io/ which do some quite powerful things with this approach. Regards, -- Rowan Tommins (né Collins) [IMSoP]