> On Jan 5, 2020, at 5:04 PM, tyson andre <tysonandre...@hotmail.com> wrote: > > I have a work in progress wrapper for allowing const-like syntax for global > constants `static const X = $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) > > ``` > const DEFAULT_PAYLOAD = json_encode(['key' => 'value']); > const ALLOWED_ELEMENT_TYPES = array_merge(self::FIRST_TYPES, > self::SECOND_TYPES); > const ELEMENT_LENGTHS = array_map('strlen', self::ELEMENTS); > ``` You and me both. -Mike -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php