tags:

views:

28

answers:

2

in a script i call another class with:

Factory::folder();

but when i specify...

dirname(__FILE__)

...i get the library's path, not the caller's.

how can i have the caller's path?

thanks

+1  A: 

Do this,

$trace = debug_backtrace();

echo $trace[1]['file']

You can even go back further.

ZZ Coder
but this is a good in production? sounds only for development
never_had_a_name
Yes. It's good in production. Whenever you have a PHP error in production, the function is invoked to print the backtrace.
ZZ Coder
No. It's only good for debugging in production - for logging etc. But definitely not for dynamic factories.
Mikulas Dite
+1  A: 

Use ReflectionClass. To be more specific, it's method getFileName().

Mikulas Dite
is that class built-in into php?
never_had_a_name
Yes, unfortunately it's not documented very well.
Mikulas Dite