note 96010 modified in language.namespaces.nsconstants by lex

From: Date: Wed, 13 Dec 2017 11:05:14 +0000
Subject: note 96010 modified in language.namespaces.nsconstants by lex
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209360@lists.php.net to get a copy of this message
Just in case you wonder what the practical use of the namespace keyword is... It can explicitly refer to classes from the current namespace regardless of possibly "use"d classes with the same name from other namespaces. However, this does not apply for functions. Example: <?php namespace foo; class Xyz {} function abc () {} ?> <?php namespace bar; class Xyz {} function abc () {} ?> <?php namespace bar; use foo\Xyz; use foo\abc; new Xyz(); // instantiates \foo\Xyz new namespace\Xyz(); // instantiates \bar\Xyz abc(); // invokes \bar\abc regardless of the second use statement \foo\abc(); // it has to be invoked using the fully qualified name ?> (Sorry, I had to use "|" instead of "\", as it was always discarded in the preview, except within a comment.) Hope, this can save someone from some trouble. Best regards. --was-- Just in case you wonder what the practical use of the namespace keyword is... It can explicitly refer to classes from the current namespace regardless of possibly "use"d classes with the same name from other namespaces. However, this does not apply for functions. Example: <?php namespace foo; class Xyz {} function abc () {} ?> <?php namespace bar; class Xyz {} function abc () {} ?> <?php namespace bar; use foo|Xyz; use foo|abc; new Xyz(); // instantiates \foo\Xyz new namespace|Xyz(); // instantiates \bar\Xyz abc(); // invokes \bar\abc regardless of the second use statement |foo|abc(); // it has to be invoked using the fully qualified name ?> (Sorry, I had to use "|" instead of "\", as it was always discarded in the preview, except within a comment.) Hope, this can save someone from some trouble. Best regards. http://php.net/manual/en/language.namespaces.nsconstants.php

« previous php.notes (#209360) next »