for a class that has introduced namespace through use, why can"t it be found without namespace when calling dynamically through variables (that is, why code snippets 1 and 2 prompt "class"A "not found")
<?php
namespace aaa;
class A
{
public static function hello()
{
echo "hello, i am " . __CLASS__;
}
}
?><?php
namespace bbb;
use \aaa\A;
// 1. namespace
// "class "A" not found"
$cls = "A";
$cls::hello();
// 2. namespacecall_user_func
// "class "A" not found"
call_user_func(array("A", "hello"));
// 3. namespace
//
$cls = "\aaa\A";
$cls::hello();
// 4. namespacecall_user_func
//
call_user_func(array("\aaa\A", "hello"));
there is an example in the namespaces section of the php manual document namespace Example-sharp3 import and dynamic names
testing this example with the code \ aaa\ A
above also indicates that no class was found. The experimental environments used are php5.3, 5.4,5.5,5.6,7.0