Re: [RFC] Constant Scalar Expressions

From: Date: Sun, 27 Oct 2013 14:27:36 +0000
Subject: Re: [RFC] Constant Scalar Expressions
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-69897@lists.php.net to get a copy of this message
On 8/15/2013 10:42 PM, Stas Malyshev wrote:
Hi!
note that we have this functionality already: $ php -r 'class A { const C = FOO; } define("FOO", 23); echo A::C;' 23 The first fetch will resolve that.
This is true, but what happens is that "FOO" is stored and then resolved on fetch with direct lookup. Now, if C = M_PI/2, what would we store? We could theoretically store string "M_PI/2" and somehow "evaluate" it, or we could even translate: class A { const C = M_PI/2; } to: class A { const C = __definition_of_A_C; } function __define_A_C() { define(__definition_of_A_C, M_PI/2); } and when we encounter __definition_of_A_C for the first time we run __define_A_C() and take the value of __definition_of_A_C - but I imaging that would seriously complicate the code, especially if we think about how to handle exceptional situations there... Stas, is there any currently existing standard "Just In Time" construct in zend? Something like a Promise?
    http://en.wikipedia.org/wiki/Futures_and_promises
If there isn't, would it make sense to add this type of feature into the core so that these types of needs could be handled with a Promise? The late binding aspect is similar in concept to a Promise I believe... -Clint

« previous php.internals (#69897) next »