I need a definition for a macro-like string in php which would literally be interpreted as this string, but I need is to refer to the line and file where the string is placed rather than my defs.php file…
define ("REDIRECT_FROM"," (".`____FILE____`." line:".`____LINE____`.")");
redirectTo("login.php",REDIRECT_FROM);
would result as:
redirected from abc.php line: 59
Hope I was clear. (the redirected from is implemented in the redirectTo() function of course)
Thanks!
You can’t do this with
define()– it sets constants, not macros.A possible solution is using a function and a backtrace:
You would then call:
You could also just build this logic into your
redirectTo()function.An example: http://codepad.org/CGUXWgAB