[PATCH] 'const' in global scope

php.internals

Chris Vandomelen

23 years ago
In tune with the current 'const' patches by Sterling, and because I found it useful (and more consistent than the original behaviour IMHO), attached is a patch which implements compile-time constants in the global scope: <?php const something = 2, something_else = 4; ?> The behaviour is the same as define(), only implemented in the compiler instead of as a function. Chris

Sterling Hughes

23 years ago
On Tue, 2003-04-08 at 15:44, Chris Vandomelen wrote:
> In tune with the current 'const' patches by Sterling, and because I found > it useful (and more consistent than the original behaviour IMHO), attached > is a patch which implements compile-time constants in the global scope: > > <?php > > const something = 2, something_else = 4; > > ?> > > The behaviour is the same as define(), only implemented in the compiler > instead of as a function. >
You'll want to use static_scalar_expr when applied with my patch. -Sterling
> Chris > > ______________________________________________________________________ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
-- "Programming today is a race between software engineers stirring to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning." - Unknown

Chris Vandomelen

23 years ago
> You'll want to use static_scalar_expr when applied with my patch. > > -Sterling
*nod* I haven't applied your patch yet (I've already got a fairly hacked up ZE2 build as it stands, having taken the time to implement features to allow objects to be casted to any primitive type (convert_to_*()) and allow overloading of the equality operator... ugly hacks. :) Chris

John Coggeshall

23 years ago
I've been thinking about this for awhile, and seeing these patches about 'const' at compile-time I thought I would throw this in here now... Instead of patching the engine for these constant values, wouldn't these things be better served in a module? I've already worked on a basic module that hooks into zend_compile() and does pre-processing before giving the script over to PHP... Hence you'd have something identical to C's preprocessing. <?php #define MYVAR 1; Echo MYVAR; ?> If there is interest, I'd like to be able to include this module in PHP5 once its been cleaned up... John -~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~- John Coggeshall john at coggeshall dot org http://www.coggeshall.org/ -~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~-

George Schlossnagle

23 years ago
On Tuesday, April 8, 2003, at 05:33 PM, John Coggeshall wrote:
> > I've been thinking about this for awhile, and seeing these patches > about > 'const' at compile-time I thought I would throw this in here now... > > Instead of patching the engine for these constant values, wouldn't > these > things be better served in a module?
Preprocessing aside (and I think something more akin to Perl's Filter support would be ideal), constant folding is nice and belongs in the engine.