|
Posted by Jiri Fogl on 11/18/71 11:44
> What's the actual difference between a function and a macro? How would use
> of macros differ from functions?
I was working on modular system, where every module was a file with
object definition.
I needed to make some global variables accessible in method of this
object (i.e. database connection object) in every module, but I wanted
to have a list of these variables only once in whole system (it would be
unpleasant to edit all modules if I decided to, for example, change name
of any of these variables).
Function is useless in this case, so I needed a macro.
I solved a problem this way:
// In initialisation part of code
define('MY_MACRO', 'global $database, $global_config,
$any_other_needed_variables;');
// In beginning of module object's method
eval (MY_MACRO);
But maybe there is much better way to do this
[Back to original message]
|