In a namespace, when PHP encounters an unqualified class, function, or constant name, it uses a different precedence policy to resolve the name. The class name always resolves to the name in the current namespace. Therefore, you must use a fully qualified name when accessing a class name that is inside the system or that is not contained in a namespace, for example:
Example #1 Accessing the global class in the namespace
<?php namespace a\b\c; Class Exception extends \exception {} $a = new Exception (' Hi ');//$a is an object of class a\b\c\exception $b = new \exception (' Hi '); $b is an object of class Exception $c = new Arrayobject;//Fatal error, A\b\c\arrayobject class not found?>
For functions and constants, if the function or constant does not exist in the current namespace, PHP will fallback to use the function or constant in the global space.
Example a fallback global function/constant in #2 namespace
<?php namespace a\b\c; Const E_ERROR =; function strlen ($str) { return \strlen ($STR)-1; } echo E_error, "\ n"; Output "Ini_all" echo, "\ n",//Output "7"-use global constants Ini_all echo strlen (' Hi '), "\ n",//Output "1" if (Is_array (' Hi ')) {//output "is not an array" echo "is array\n"; } else { echo "was not array\n"; }? >