Re: [RFC][Vote announcement] Arbitrary static variable initializers

From: Date: Thu, 16 Mar 2023 11:51:05 +0000
Subject: Re: [RFC][Vote announcement] Arbitrary static variable initializers
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-119722@lists.php.net to get a copy of this message
Hi Tim > Using Alain's example of static variables that depend on each other. For > the following: > > function foo() { > static $a = 0; > static $b = $a + 1; > } > > The value of '$a' is known at compile time. Is the value of '$b' also > known at compile time? It might make sense to include that as an > explicit example in the RFC (examples are cheap). Interesting thought. $a's initial value is known at compile time, but $b's isn't because it doesn't depend on $a's runtime value by the time it reaches $b's initialization. This value could change between $a and $b's initialization through direct assignment, by-ref modification, or even access by-name which is not easily detectable. I've added a section to the RFC to explain how this works in more detail. https://wiki.php.net/rfc/arbitrary_static_variable_initializers#what_initializers_are_known_at_compile-time Let me know if anything is still unclear. Ilija

« previous php.internals (#119722) next »