F
F
Freud's cat2019-01-19 09:29:52
PHP
Freud's cat, 2019-01-19 09:29:52

Why doesn't class_exists find the class connected by composer's autoloading?

Actually, subject. returns . But if you write the full name of the class , then everything is located. For several hours I have been reading literature on namespaces and specifically on the autoloader, but I still don’t understand why the search function does not understand the short class name, but understands the full one. Can anyone explain?)
class_exists('MyClass');falseclass_exists('App\Classes\MyClass');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2019-01-19
@medbrat69

Autoloading has nothing to do with it, it's just that class_exists expects to get the full path to the class along with the namespace, it does not understand the aliases of the current file.
You need to manually add the namespace to the check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question