How do I define macros in PHP. I need to write them for some code, hence [man]define/man will not work:-
Whenever I include a file I need to exec about 20 lines of code to decide whether to include a file or not, perform security checks etc.
// line 1
// line 2
// line 3
// ...
// ...
// ...
// line 18
if($file_should_be_included) {
include_once("/path/to/file");
}
writing this code everytime I have to include a file is tedious.
I need macros that will replace SPECIAL_INCLUDE("/path/to/file");
will the above code.
I cannot use function for this because:-
function special_include($filename) {
// line 1
// line 2
// line 3
// ...
// ...
// ...
// line 18
if($file_should_be_included) {
include_once("$filename");
}
}
In this scope of file included will get limited to this function only, and I wont be able to use the file outside this function.
I was able to think of a workaround in which the function will return the source of the file and we can "eval" it. but that makes code look ugly.
since i have to use something like
eval(source_of_file_to_be_included($filename));
I want it to be simply:
SPECIAL_INCLUDE("/path/to/file");