On Mon, 2003-08-18 at 20:56, Cristiano Duarte wrote:
> Is possible to implement userland macros in a PHP extension or it can
> only be implemented in the core?
A "userland" solution could be to use cc -E on your .php files.
> I know that macros is a preprocessor task and I think PHP has no
> preprocessor (does it?).
It doesn't.
> So it's possible to implement a preprocessor ?
It's possible, of course, but PHP needs to compile fast as (without any
accelerator products whatsoever) this is what happens on each request to
a script. A preprocessor takes up more time and IMHO only makes sense in
compiled languages (in the original sense of "compiled":)).
> An example (or something like that):
[...example...]
thekid@friebes:~ > cat prep.phpc
<?
#define DEFAULT_VALUE(check_value, default_value) \
(isset(check_value) ? check_value : default_value)
$a = DEFAULT_VALUE($my_array['some_index'], true);
?>
thekid@friebes:~ > cc -P -C -E -x c prep.phpc
<?
$a = (isset( $my_array['some_index'] ) ? $my_array['some_index'] :
true ) ;
?>
Notes on command line arguments passed to cc:
-E execute preprocessor only
-P do not generate #<line> comments
-x c Set language to "C".
-C leave comments intact
You might also want to do a grep -v '^$' to get rid of some of the
whitespace leftovers by the preprocessor.
- Timm