example
index.php //I know where this file is
$class = new childclass();
$class->__initComponents();
somefile.php //I know where this file is
Class childclass extends parentclass {
}
someparentfile.php // I don't know where this file is
Class parentclass {
function __initComponents(){
//does something
}
}
I need to find out where someparentfile.php is.
reason:
I am debugging some difficult php code that someone else wrote, I need to find out what file contains the code that defines a class parameter.
I found it as far as a class method calling a function that does this:
$class->__initComponents();//the parameter is defined somewhere in there
The problem is that this function is within a parent class "MyClass" of the above $class, and I have no idea where the parent class is.
is there a way or some debug function by which I can find out the location of this parent class or at least where the parameter was defined?
p.s. downloading the whole application and then using text search would be unreasonable.
The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.
dirname(__FILE__) allows you to get an absolute path (and thus avoid an include path search) without relying on the working directory being the directory in which bootstrap. php resides. (Note: since PHP 5.3, you can use __DIR__ in place of dirname(__FILE__) .)
If you are using PHP 7.0 and above then the best way to navigate from your current directory or file path is to use dirname(). This function will return the parent directory of whatever path we pass to it.
For the current folder of the current file, use $current = dirname(__FILE__); . For a parent folder of the current folder, simply use $parent = dirname(__DIR__); . Save this answer.
You can use Reflection
$object = new ReflectionObject($class);
$method = $object->getMethod('__initComponents');
$declaringClass = $method->getDeclaringClass();
$filename = $declaringClass->getFilename();
For further information, what is possible with the Reflection-API, see the manual
however, for the sake of simplicity, I suggest to download the source and debug it local.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With