ladybug
ladybug copied to clipboard
Uncaught reflection exception
It would be nice if ladybug could catch this Exception and make some more descriptive information rather then letting PHP crash on a Fatal Error.
<?php
class Foo {
public function publicFunction() {
$this->privateFunction($this, null);
}
private function privateFunction($that, Bar $undefinedObject = null) {
ldd($that);
}
}
$b = new Foo();
$b->publicFunction();
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Bar does not exist'
Relevant documentation: http://www.php.net/manual/en/reflectionparameter.getclass.php
I have looked into this and we can definitely detect this issue in runtime but I am not sure about how to alert the user in the dump process
I have been able to intercept the problem with this dirty hack around https://github.com/raulfraile/ladybug/blob/master/src/Ladybug/Type/Object/Container.php#L389:
try {
$class = $methodParameterReflected->getClass();
} catch (\ReflectionException $e) {
// This happens if the Class does not exist
$methodParameter->setType('Wrong_Typehint!');
}
With this, ldd works just fine and when dumping the signatures of the method, this Wrong_Typehint!
warning appears but I am not sure about how to make it more relevant to the user
Ideas @raulfraile ?