Re: [RFC][Under discussion] Fetch properties in const expressions

From: Date: Fri, 03 Jun 2022 13:26:16 +0000
Subject: Re: [RFC][Under discussion] Fetch properties in const expressions
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-117849@lists.php.net to get a copy of this message
On Thu, Jun 2, 2022 at 8:17 AM Ilija Tovilo <tovilo.ilija@gmail.com> wrote: > > Hi Nikita > > > This looks like a reasonable addition. > > > > Could there be any expectation that if -> works, ?-> does as well? > > Possibly. The implementation was simple enough so I'll add support for > completeness. > > --- > > Hi Côme > > > It is not clear to me why this allows using -> on enums but not on other objects. > > The RFC *does* allow using -> on all objects. From the RFC: > > > As mentioned, the primary motivation for this feature are enums. However, the > > implementation for supporting new is identical and I don't believe > > arbitrarily restricting how -> can be used in this context makes sense. > > > Can you clarify why the following is not allowed: > > > > <?php > > > > $a = new Thing(); > > > > class C > > { > > protected $b = $a->var; > > static $staticobj = new Thing(); > > function f($p = self::$staticobj->var) {} > > } > > protected $b = $a->var; is not allowed because there > can't be local > variables in the context of context expressions. `function f($p = > self::$staticobj->var) {}` is not allowed because static variables > aren't supported in constant expressions. Your examples would already > fail today without ->. > > Ilija > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > The RFC *does* allow using -> on all objects. From the RFC: 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?

« previous php.internals (#117849) next »