Finding the PHP File (At Run Time) Where a Class Was Defined

Finding the PHP File (at run time) where a Class was Defined

Try ReflectionClass

  • ReflectionClass::getFileName — Gets a filename

Example:

class Foo {}
$reflector = new \ReflectionClass('Foo');
echo $reflector->getFileName();

This will return false when the filename cannot be found, e.g. on native classes.

preloaded php class file location

Check the include path(s) to see which directories are relevant.

get_include_path

http://php.net/manual/de/function.get-include-path.php

Use Reflection class to get the actual file
http://de1.php.net/manual/de/reflectionclass.getfilename.php

Find out the directory where the class instance was created?

Yes, you can use debug_backtrace()

class A {
function __construct() {
var_dump(dirname(debug_backtrace()[0]['file']));
}
}

PHP: unable to locate functions being used (seemingly not defined)

Maybe the class was included in a php file that is including some external libraries? The functions might be taken from these libraries.

Get name of file which run function/class in PHP

See debug_backtrace.

In your MySql class you can simply call this function, and trace the call to it's origin.

PHP: Class file in the same directory not being recognized?

make sure you're actually declaring the class in your class file

class tattler_stats {
// class code here
}

if you are already doing that, try specifying the path more concretely:

include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.tattler_stats.php');


Related Topics



Leave a reply



Submit