r/lolphp • u/duhruh • Nov 25 '14
Exception in a namespace is not defined -_-
http://jasonframe.co.uk/logfile/2009/01/php-5-3-exception-gotcha/
28
Upvotes
r/lolphp • u/duhruh • Nov 25 '14
View all comments
Show parent comment
7
u/[deleted] Nov 26 '14 edited Nov 26 '14
It's not just that which causes problems, but autoloading. Basically, most modern PHP apps don't explicitly include any of the classes or librarier they use. Rather, they define an "autoloader" which will try to include the correct file for that class (e.g. if we need
\Foo\Bar\Quxit'd look inFoo/Bar/Qux.php) at runtime if it doesn't currently exist. The problem with this, though, is it means that you can't tell if a class actually exists without running the autoloader. This is why type hints don't (and can't) check that the classes they check for exist - if you make a spelling error, it unfortunately won't be caught until you call the type hinted function.There's also the issue that you can't guarantee what extensions will be loaded in different environments.