Catching Reflection Exception When Parent Class Not Found
Scenario: I have a class that extends another class, yet the parent class is undefined (for whatever reason). I am trying to get a ReflectionClass of the child class. When I do this, I get a Class Not Found exception on the parent class. However, I cannot catch this exception. What am I doing wrong?
For example...
<?php
class Foo extends Bar { }
try
{
$class = new ReflectionClass('Foo');
echo 'I\'ve reflected "Foo" successfully!';
开发者_开发问答}
catch (Exception $e)
{
echo 'My exception handler';
}
The result of the above code is a printout of the class 'Bar' not found exception. Why is my catch statement not picking up the exception?
thanks, Kyle
That's because the exception occurred on this line and not on the lines after try
:
class Foo extends Bar { }
I tried it, putting the class declaration on a try-catch
won't work too. Make sure Bar
is included first.
精彩评论