# [PATCH] 'const' in global scope

- Thread: https://externals.io/message/806
- Original archive: https://news-web.php.net/php.internals/806
- Started by Chris Vandomelen on 2003-04-08T19:44:56+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #807 — Sterling Hughes — 2003-04-08T19:20:58+00:00

URL: https://externals.io/message/806#807 · In reply to: #806

> 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
> 
> ______________________________________________________________________
> 
> -- 
> 
> 
-- 
"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

---

## #806 — Chris Vandomelen — 2003-04-08T19:44:56+00:00

URL: https://externals.io/message/806#806

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

---

## #809 — John Coggeshall — 2003-04-08T21:33:51+00:00

URL: https://externals.io/message/806#809 · In reply to: #806

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/
-~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~-


>-----Original Message-----
>From: Chris Vandomelen [mailto:chrisv@revhosting.com] 
>Sent: Tuesday, April 08, 2003 3:45 PM
>To: internals@lists.php.net
>Subject: [PHP-DEV] [PATCH] 'const' in global scope
>
>
>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
