the autoloader at the beginning of my php code
function __autoload($class_name) {
include_once $class_name . '.class.php';
}
is causing a call to new MongoClient(); to fail with the error Warning: include_once(MongoClient.class.php): failed to open stream
How can I use the autoloader for my classes and still use the standard classes?
Note: MongoDb has been installed with PECL and works fine with the autoloading function removed. mongo-1.3.0beta2 on php 5.4.9
__autoload(), if defined, is called each time you try to access a class that has not been imported manually usingrequire_once()orinclude_once()and is not part of the PHP internal classes.In your case the
__autoload()is triggered although you try to access a PHP internal class –MongoClientthat is provided by the php-mongo extension. When you are not using__autoload()it works as expected.It looks like the extension doesn’t speak well with the PHP interpreter. You should first try an update from the beta to the stable 1.3.1 version. If this won’t help, it will need further investigation.
Btw, if you try to instantiate a
MongoClientobject inside a namespace use\MongoClient(), like this:The
\refers to the global namespace.