dynamic access magic constants in php

Posted by Radu on Stack Overflow See other posts from Stack Overflow or by Radu
Published on 2010-03-19T13:01:45Z Indexed on 2010/03/19 13:11 UTC
Read the original article Hit count: 199

Filed under:
|

Hello,

Is there a way to shortcut this:

function a($where){
  echo $where;
}

function b(){
  a(basename(__FILE__).'::'.__FUNCTION__.'()::'.__LINE__);
}

to something like this:

    define("__myLocation__", ''.basename(__FILE__).'::'.__FUNCTION__.'()::'.__LINE__.'');
    function a($where){
      echo $where;
    }

    function b(){
      a(__mYLocation_);
    }

I know that this cannot be done with constants (is just an theoretical example), but I can't find a way to shorthen my code. If a use a function to get my line it will get the line where that function is not the line from where the function was called.

I usualy call a function that prints directly to the log file, but in my log I need to know from where the function was called, so i use basename(__FILE__).'::'.__FUNCTION__.'()::'.__LINE__ this will print something like:

index.php::b()::6

It is a lot of code when you have over 500 functions in different files. Is there a shorten or better way to do this?

Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about php5