I had spl_autoload_register, which worked fine, but then I decided to add some namespaces to ensure PSR2 compliance and can't get it working.
Strcuture reference:
-index.php
-classes/
-Class1.class.php
-Class2.class.php
-Class3.class.php
Each class begins with:
namespace Foo;
Class ClassX {
Index.php:
<?php
spl_autoload_register(function($class) {
include 'classes/' . $class . '.class.php';
});
$myObj = new Class1();
echo $myObj->doSomething();
This product displays an error. Fatal error: Class 'Class1' not found in /var/www/myApp/index.php on line X
My first thought was that I needed to use a namespace with my instance, so I changed index.phpto:
$myObj = new Foo\Class1();
However, then I get
Warning: include(classes/Foo\Class1.class.php): failed to open stream: No such file or directory in /var/www/myApp/index.php on line 6
If in manual mode everything works fine, include 'classes/Class1.class.php';etc.
source
share