Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108686 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35753 invoked from network); 19 Feb 2020 20:45:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Feb 2020 20:45:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E7AF218050B for ; Wed, 19 Feb 2020 11:00:58 -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.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, 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-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 ; Wed, 19 Feb 2020 11:00:58 -0800 (PST) Received: by mail-qk1-f174.google.com with SMTP id a2so1118803qko.12 for ; Wed, 19 Feb 2020 11:00:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=7ogJsH0I0nMNjR5gXAkweTQdcxVIQw1e3sMyf3PGqaI=; b=G5oks5LZBLHsuRB8JRCjDvQId4ZwRvDvY0DkC6VyoDZLSp7CAXIm9zBdUxp9ADaFL9 Bc7pRXo+VoZ9lI6Gx0yNKTjGjZ3powqupfXonm/PlMn9OYsp+hFMbO0dE4CamPuC/Ubm IqbTaQMQwkmMA6DtZemcxmzRRqYEFg015deNPYmqjPJQpK0nv5pcEkPpczBOChRuADaQ RfnCOvI/PZsVf7KwN2oFHarK4bMKinsCGxtemirJnepMjx97M4AdS3Asr3QyCpmqp4kl /ZI2htLSDWpR+k1xqDTtM16fDOOFV33cenbUNQVkkd1IELZNhgqlKbmLiE0bN/lpcfCw k9Eg== X-Gm-Message-State: APjAAAVTxJD5bHGg0Ai/wvxW+LYvXuvRnBiR8EQ9BwZLsLLrScYYY6ZH oqAbZDlLQLG5TrTo7Ga3gfoD3P4gE8WH9wqDckE= X-Google-Smtp-Source: APXvYqyPC/TGOw2C94D+YCepLyUFPMMTsoLMqnTgH6IrUsvLC9MnzvPsPDCIt3gXuWGM4Za7NikuIQ5wdEROVM+eMc4= X-Received: by 2002:a05:620a:24d:: with SMTP id q13mr22437600qkn.99.1582138855737; Wed, 19 Feb 2020 11:00:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: bishop@php.net Date: Wed, 19 Feb 2020 14:00:20 -0500 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="0000000000007b5266059ef268a9" Subject: Re: [PHP-DEV] Re: Straw poll: Places to allow function calls in constant expressions From: bishop@php.net (Bishop Bettini) --0000000000007b5266059ef268a9 Content-Type: text/plain; charset="UTF-8" On Wed, Feb 19, 2020 at 12:58 PM tyson andre wrote: > Hi internals, > > > I've created a straw poll at > https://wiki.php.net/rfc/calls_in_constant_expressions_poll , to measure > interest in allowing calls in different types of constant expressions. > > If there aren't any problems with the poll structure or rules preventing > creating a poll, I was going to add it to the rfc index page and move it to > voting. > > This straw poll has been moved to voting and added to the rfc index page. > The poll will be closed on March 4th. > The original motivation was, IIRC, to initialize class constants with an expression. Following KISS, I feel we should constrain our efforts to that scope, and that's how I voted: "Yes" on class constants and static members, "No" on everything else. As for implementation, we must manage the complexity. I'm a hard "No" on restricting use to an arbitrary, variable list of blessed functions. It's a dev UX nightmare to include a bevy of array_* functions but no str* functions. Consequently, the only way to safely initialize class constants and static members is at run-time, and I can only think of one way to do it. Apologies if this has already been suggested: taking a cue from C#, a static class constructor ([1]) would allow us to have expression-initialized constants and static members. url; self::$mtime = filemtime('config.json'); } public function reload() { if (self::$mtime < filemtime('config.json')) self::__constructStatic(); } } } echo Config::URL; // assert: runtime has already called _constructStatic $config = new Config; // assert: __constructStatic called only once by runtime $config->reload(); // instance may call its own static constructor ?> Trying to do the same for global constants, static variables, or function default parameters resists a similar initialization mechanism because we don't have defined common entry point analogues. If we had a main(), or if we had framed @before decorators, we could do something similar, but we don't -- so I feel we should leave these off the table. Thank you, Tyson, for taking the time to progress this feature. [1]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors --0000000000007b5266059ef268a9--