spl_autoload_register and namespaces issue
-
28-03-2021 - |
문제
Why this is returning Fatal error: Class 'Mynamespace\String' not found in ...:
set_include_path(get_include_path().PATH_SEPARATOR.'library/');
spl_autoload_extensions('.php');
spl_autoload_register();
Mynamespace\String::myfunc('Test');
My library/String.php is:
<?php
namespace Mynamespace;
class String
{
static function myfunc($needle)
{
echo $needle;
}
Please not if I remove the namespace it works fine.
해결책
spl_autoload_register()
without params registers just spl_autoload()
.
And that default autoloader does not transpose namespaces onto directory names or anything. It just lowercases the received class name, and appends a .php
suffix. Therefore namespaced classes will only work on Windows, accidentally.
제휴하지 않습니다 StackOverflow