2010-11-23

PHP namespaces and autoload on UNIX

The namespace "path" symbol is backslash. Therefore, the full class name looks like:
MyNameSpace\MyClass. We need to replace the backslash with slash in the __autoload function, in order for it to work under UNIX. Under Windows, it works either way.

function __autoload( $class_name ) {
# ------------------------------------
$class_name = str_replace( '\\', '/', $class_name );
require_once $class_name . ".class.php";
}

No comments:

Post a Comment