Is possible to implement userland macros in a PHP extension or it can
only be implemented in the core?
I know that macros is a preprocessor task and I think PHP has no
preprocessor (does it?).
So it's possible to implement a preprocessor ?
An example (or something like that):
<?
#define DEFAULT_VALUE(check_value, default_value) (isset(check_value) ?
check_value : default_value)
$a = DEFAULT_VALUE($my_array['some_index'], true);
?>
Best regards,
Cristiano Duarte
Cristiano Duarte wrote:
Is possible to implement userland macros in a PHP extension or it can
only be implemented in the core?I know that macros is a preprocessor task and I think PHP has no
preprocessor (does it?).So it's possible to implement a preprocessor ?
I think you can use stream wrappers with some limitations (definitions
should be in different file than their use).
Regards,
Wojtek
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
[...]
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
Oops, almost forgot: You can use -imacros <filename> if you want to put
your macro definitions into a seperate file.
- Timm