Re: Initializing constants once, with code?
| From: | tyson andre | Date: | Sat, 25 Jan 2020 03:37:22 +0000 |
| Subject: | Re: Initializing constants once, with code? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108238@lists.php.net to get a copy of this message | ||
I've also put together a *different* proof of concept adding support for named calls of global
functions
(and only that, no other new allowed types of expressions) from within the expressions of constants.
(i.e. global constants, class constants, and parameter defaults).
I was considering putting together an RFC to allow function calls
once I'm finished implementing that,
and if no major unfixable issues are identified.
https://github.com/TysonAndre/php-src/pull/12
allows expressions such as:
<?php class X { const MESSAGE = sprintf('hello, %s', 'world'); }
This uses php's default behavior for evaluating constants,
which is delayed until the first use for class constants/param defaults,
and at the time of declaration for global constants.
This POC will throw if the constant would be invalid (same checks as define()) (e.g. reject cycles,
references, or objects),
and will also throw an Error if a function call tries to load the constant currently being defined.