I’ll like to know if this is a bug or wrong implementation ….. am try to check if class_exist
My Class
namespace servers\testing ;
class HelloWord
{
function hello()
{
echo "hello World" ;
}
}
Testing
use servers\testing\HelloWord as OkWorld ;
$okWolrd = new OkWorld() ;
$helloWorld = new \servers\testing\HelloWord() ;
var_dump($okWolrd); //object(servers\testing\HelloWord)[1]
var_dump(class_exists('servers\testing\HelloWord')); //true
var_dump(class_exists('OkWorld')); //false
$declearedClasses = get_declared_classes() ;
var_dump(in_array('servers\testing\HelloWord', $declearedClasses)); //true
var_dump(in_array('OkWorld', $declearedClasses)); //false
var_dump($okWolrd instanceof $helloWorld); //true but OkWolrd needed to be initiated before it works
Question
Does it mean that OkWord is not a valid PHP class ?? note that new OkWorld() works fine.
How do you verify that OkWord exists without deceleration ?
Edit 1
I know that OkWorld is an alias but its a reference to servers\testing\HelloWord which is a valid class …
Thanks
I think it’s neither a bug nor a wrong implementation.
OKWorldis not a class, it’s an alias, the interpreter will replace it withHelloWordwhenever it exists. But the interpreter will not search the strings, so the functionclass_existswill get the stringOKWorldand search for the corresponding class, which doesn’t actually exist! What actually exists is an alias.