Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Trailing Slash

Do we really need to use trailing slash ?

$di = new \Phalcon\DI\FactoryDefault();

Because it works just fine without it.

$di = new Phalcon\DI\FactoryDefault();

The only thing I see diferent is syntax highliting color in Sublime.


If no namespace was declared at the top of the file then it it not necessary to declare the global namespace with the trailing slash


That's a leading slash. Trailing would be at the end.

Namespace declarations kind of work like a directory structure. Without a leading slash, the namespace can be thought of as "relative", whereas the leading slash treats the declaration as "absolute". Like @david-duncan said, if you're not inside a namespace, then the relative and absolute namespace declarations will point to the same thing.

If, for example, you have declared the "Foo" namespace at the top of the file, then your second example would be resolved to: \Foo\Phalcon\DI\FactoryDefault.


@ quasipickle, you're right ... leading slash ... sorry! Thanks for the info guys.