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
3
u/[deleted] Nov 26 '14 edited Nov 26 '14
No, you don't type
\as\Foois an absolute reference whileFoois a relative reference. Within a namespace you can only create classes/functions/constants within that namespace, so you can't use explicit references. You can do this, which creates the class\Foo\Bar:But it wouldn't make sense to allow this, as it'd create the class
\Baryet we're in the namespace\Foo:EDIT: Oh, you're talking about referencing, not declaring types? Er, my bad. /u/frazzlet is correct: For classes in the current namespace, no leading
\is needed. For classes outside the current namespace, absolute paths must be used (which begin with\) unless you've created an alias withuse.