Zacząłem bawił cię autoloadem i napotkałem na problem:
Struktura katalogów:
projekt
--index.php
--class
----context.php
I jeśli zrobię:
include __DIR__.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'Context.php';
$context = new Context();
to wszystko działa
Tak też działa:
set_include_path(__DIR__.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR);
include 'Context.php';
$context = new Context();
Natomiast gry próbuję dodać autoload:
set_include_path(__DIR__.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR);
spl_autoload_extensions(".php");
spl_autoload_register();
$context = new Context();
Dostaje błąd:
Fatal error: spl_autoload(): Class Context could not be loaded
Zgodnie z dokumentacją na http://php.net/manual/en/function.spl-autoload-register.php
nie trzeba robić czegoś takiego:
function my_autoload ($pClassName) {
include(__DIR__ . "/" . $pClassName . ".php");
}
spl_autoload_register("my_autoload");
Powinno wystarczyć samo spl_autoload_register(); które skorzysta z domyślnej funkcji spl_autoload.
Moje pytanie co jest źle?