Re: [RFC] Constant Scalar Expressions
| From: | Stas Malyshev | Date: | Fri, 16 Aug 2013 03:42:12 +0000 |
| Subject: | Re: [RFC] Constant Scalar Expressions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-68545@lists.php.net to get a copy of this message | ||
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...
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227