Ask the question of a static method that calls the variable class name of another command space

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

clipboard.png

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

, respectively.
Php
Jun.27,2022
The namespace in

call_user_func is the root namespace. Cannot be introduced using relative namespaces. So \ aaa\ A executes normally. See https://stackoverflow.com/que...

Menu