I have mixed emotions on the yes/no side of things, but on the "how" side,
I think we can do this fairly easily.

During parse, when a non-scalar const expression is encountered, the actual
binding to the class is deferred, and bytecodes are emitted in the "(main)"
function.  To put it in psuedo-code terms:

<?php
class Foo {
  const bar = M_PI / 2;
}

Gets turned into:

<?php
class Foo { }
runkit_constant_add('Foo::bar', M_PI / 2);

Though obv, in reality we wouldn't use runkit_constant_add(), it'd be a new
opcode which had the same effect.  This is basically transparent to opcode
caches, allows the constant to actually change based on runtime conditions
(if you were foolish enough to make your constant so non-constant), and
leaves the syntax used by the user looking like a normal constant
declaration.

-Sara

Reply via email to