On Fri, Jun 3, 2022 at 3:26 PM Robert Landers <landers.rob...@gmail.com> wrote: > > So, how does this change our mental models when writing PHP? For > example, I generally consider `const` to be a "compile-time" constant > (ie, generated/created before any code is actually executed). So would > this allow code to actually execute before any other code (ie, by > putting code in a __get()) and thus cause issues due to database > drivers and etc to not be loaded yet -- or cause them to be loaded > prematurely?
True but that's already the case since PHP 8.1 and https://wiki.php.net/rfc/new_in_initializers (https://github.com/php/php-src/pull/7153), e.g. https://3v4l.org/MSWi0: ``` class Foo { public function __construct() { echo "Side effect!\n"; } } const C = new Foo(); ``` but as https://externals.io/message/113347#113607 says, "side-effecting constructors are a terrible idea", and same can be said for "side-effecting [magic] getters"... Also note that this only concerns *global* (or namespace-scoped) constants (which can also be defined "dynamically" with `define()`), not *class* constants. -- Guilliam Xavier -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php