Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108011 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62099 invoked from network); 6 Jan 2020 21:12:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2020 21:12:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 924C21804F6 for ; Mon, 6 Jan 2020 11:17:16 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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 11:17:15 -0800 (PST) Received: by mail-yb1-f173.google.com with SMTP id z10so15180766ybr.9 for ; Mon, 06 Jan 2020 11:17:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ud8DIEklVeyrkUBvU3EzJjzlzYlCQzE0/ARqpafGfXM=; b=yIv/CZm440RQkSH6NNtNmum36RJiexTOVeZmO9seuSBQskABLBmaHTdDJanm7hLZjX qzbG9fNP9vTI1eKNjvX7SuYA6bLcZj1iCmQ7NYk4qoideqsekCvNK3mqjoQBVphd/mjf Xgu+uXUeY2Go+DKz2eRO4DN6mAe+wrmQ8T5NSOfxIFB5S3uCiEtmGFSTcRT0swB0Pz/w TR3AtNYQTsnFJCJIkts2hWq04iyuM6ZHAY/3P9+kQe+bX7fiWqDl0snL1znXIHGCU3om GyxZL0aXI2HPHC3lXXeuKCRvQSNW8hnSJr5BbuoI35tnFus78vVD1gfDhDMiWD/Jm02J kFfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ud8DIEklVeyrkUBvU3EzJjzlzYlCQzE0/ARqpafGfXM=; b=B89VeTO7wuLeEPKErBy+W6ZXlCyaO66zsoN79kO3ySZA9AeKhlzDZIdtXWxfIX2Ukr T4fZLT7wA57YtGa8jC7r9F3Z3+scXdQbDDGhnYwKSFkRQ7UJBsU606HG6LmppbdTiYQM QY3TSKG0MjmYYw9waiL0wBaCEI5eT3OMOoj+eDRQCDGIyMmSKfB7aPf8eswc9QxsPZPM vIFQvtYGDPN+8S8wh7Iv9qq2DZAXqQ72RrAcg6MV090fOyDV2GP/OE7in7qQa/vxMu8c UDQ51D6UjuTV1cwBp39uc4w82yfuoUSTlOQiZCwz4CtycLPfkIeUwGpqpe+OYLehsgir N0qA== X-Gm-Message-State: APjAAAVcMIj/rKlsRlu/dpiZwH3+lekrNf/AV/6DgM5P5zZAoQGYx1hJ lgnL0ADGAKHwdF1A/+FAg7qfxw== X-Google-Smtp-Source: APXvYqxR4USXxq7jKEPdQOVI1Lwh4oIFRJo12aehOxdgA3xKruy4Kx402Ecg2NmfvGk7e3PyBPad+Q== X-Received: by 2002:a5b:14b:: with SMTP id c11mr75599374ybp.14.1578338232958; Mon, 06 Jan 2020 11:17:12 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:d059:ddab:12ae:4ac7? ([2601:c0:c680:5cc0:d059:ddab:12ae:4ac7]) by smtp.gmail.com with ESMTPSA id 144sm28372344ywy.20.2020.01.06.11.17.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jan 2020 11:17:12 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Mon, 6 Jan 2020 14:17:10 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> To: tyson andre X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Initializing constants once, with code? From: mike@newclarity.net (Mike Schinkel) > On Jan 5, 2020, at 5:04 PM, tyson andre = wrote: >=20 > I have a work in progress wrapper for allowing const-like syntax for = global constants `static const X =3D $dynamicExpression;`. > This can be seen in https://github.com/TysonAndre/php-src/pull/10 Thanks for replying and including this. Nice work. > - Eagerly initialized dynamic constants are easier to reason about in = some ways (e.g. fetching the constant of an already fetched class is = less likely to cause pauses or exceptions.) > This makes un-noticed errors in rare code paths less likely. > - Attempting to support function calls, property accesses, class = constant accesses (e.g. inherited), and variables in class constants = recursively and/or lazily > would probably break a lot of code/assumptions in the php engine. Frankly my strong preference would be for on-demand initialization = because otherwise each page load could end up running lots of code to = calculate values that are never used on the particular page. > My preference would be to make it easier to use dynamic expressions, = and recommend in coding guidelines that > certain types of expressions "SHOULD NOT" be used for constants that = vary on a particular host. > (network calls, time, etc) >=20 > ``` > const DEFAULT_PAYLOAD =3D json_encode(['key' =3D> 'value']); > const ALLOWED_ELEMENT_TYPES =3D array_merge(self::FIRST_TYPES, = self::SECOND_TYPES); > const ELEMENT_LENGTHS =3D array_map('strlen', self::ELEMENTS); > ``` You and me both. -Mike=