Possible Duplicate:
php: determine where function was called from
I have an autoloading function my_function($class)
that could be called by any script. It is called by PHP's spl_autoload_call()
and that can happen everywhere. How do I script my_function($class)
to detect when it is called by a specific $file
?
Something like:
$file = '/htdocs/project/whatever.php';
if ($caller_file == $file) {
...
How do I find $caller_file
?
I do understand this question is confusing but I can't put it in better words right now. So if you have any problem understanding just let me know in the comments.
Edit (Context) I want to make the script load a different class's file if the file the autoloader would load is the same in which the autoloader is called.
For example giving:
namespace Something;
class Random extends Random {}
should not load itself, but a different file in which we have:
namespace Something;
class Random { ... }
In other words:
What if I'm defining MyName\Class
in a/class.php
and I want to extends itself with MyName\Class extends \MyName\Class
(inside a/class.php
) but I want the autoloader to look \MyName\Class
in b/class.php
when it is asked within a/class.php
?