3

I have a function log($text)

all this does is write $text to a database.

I would like to include __LINE__ and __FILE__, but don't want to include it as a parameter each time as I currently do:

function log($text,$file = null, $line = null){
    // write $text to db using the three paramters
}

If I change $file = null to $file = __FILE__ it uses the file name that the function lives in, rather than where the function is being called.

Is there any way around this?

Although the question is identical, the answers seem to focus on some other topic: function name($param, $line = __LINE__, $file = __FILE__) {}; also, not using Zend framework: how to have php get the __LINE__ or __FILE__ value where a function is called

Community
  • 1
  • 1
d-_-b
  • 21,536
  • 40
  • 150
  • 256
  • 6
    The question you linked to seems to me to answer the question fine - the key insight is that you need to use [`debug_backtrace()`](http://php.net/debug_backtrace) to find where the function was called from. – IMSoP Jun 10 '13 at 03:10
  • possible duplicate of [function name($param, $line = \_\_LINE\_\_, $file = \_\_FILE\_\_) {};](http://stackoverflow.com/questions/3387320/function-nameparam-line-line-file-file) – IMSoP Jun 10 '13 at 03:11
  • Ohhh, ok , I didn't get why everyone was using that name I thought it was implied by something else. So that's the function I need to use, aye? – d-_-b Jun 10 '13 at 03:11
  • thanks @IMSoP and thanks for the edit on that question :) – d-_-b Jun 10 '13 at 03:13

0 Answers0