ladybug icon indicating copy to clipboard operation
ladybug copied to clipboard

Uncaught reflection exception

Open flip111 opened this issue 10 years ago • 1 comments

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

flip111 avatar Jun 12 '14 07:06 flip111

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 ?

ricardclau avatar Aug 23 '14 09:08 ricardclau