Is there any way in php to create macros for inline execution of code
without creating scoping issues like function() does.  For Example:

if you had a macro set up so like this
Macro($x) {
    for($i=0;$i<$x;$i++) {
        echo $x;

and a program like this



you could call this macro an php would basically make the substitutions
and execute the code within the current scope of the program without
dropping into the scope of a function.  Although this would be
inefficient for most things it could be a useful for some applications.

The reason I am looking to do this is because I have a very large
codebase of php scripts that are broken into modular pieces.  I have a
function called Uses($includes) that allows you to pass in a string of
include files.  Uses() runs through a loop to include the files but,
because Uses is a function all variables within the included files go
out of scope when the function executes.  Many of the included files
have defined global variables that are defined for use with the included
file.  If there were some sort of Macro syntax then every time the Macro
is called the code is copyied and in-lined executed within the current
running scope.  There may be way to do this.  For some scripts with
complicated and nested includes the uses() function might get called
several times to include files needed by submodules of modules.  I could
do this with the include function but the way we have it set up it makes
the scripts easier to read.

i.e. Uses("Sql Date Http Browser") would include the and without having to specifiy

the current uses function looks like this
Uses ($includes);
  $libs=explode(" ",$includes);
  for ($i=0;$i<count($libs);$i++) {
    $filename= trim(strtolower($libs[$i])) . '.inc.';

Any feedback would be appreciated.

John Woolbright

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to