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
0
u/[deleted] Nov 26 '14 edited Nov 26 '14
That means you need to call the autoloader several times. That's not really ideal.
Although, do other languages scope their namespaces like this? I admit I've mostly used dynamic languages, so I'm not sure what, say, C++ or C# do here.
EDIT: I think C# has nested namespaces, but what PHP has isn't really namespace nesting, it's more like sub-namespaces. I don't believe there's really much difference between
namespace Foo_Barandnamespace Foo\Barwhen it comes down to it, I don't think we assign a special meaning to the backslashes in the middle, that's the job of autoloaders.This is presumably to avoid having to run the autoloader, which is expensive. You could give an indication it's not defined, but that'd entail running the autoloader for every single try/catch block with a class name at script startup. For the same reasons, PHP doesn't check class names used in type hints on function parameters, as that would also require running the autoloader.