views:

111

answers:

3

I am using __autoload() which simply looks like this:

function __autoload($class_name) {
  require_once($class_name . '.class.php');
}

When the error reporting is E_ALL it works fine. The class is loaded, and the script runs without errors.

When the error reporting is E_ALL | E_STRICT, no pages work, I simply get:

"Fatal error: Class 'NameOfClass' not found in \path\to\current\script on line 0"

Why? Is this expected behaviour when using __autoload() or is it a problem with my script?

+1  A: 

Well, if you include a file, and the class is still not loaded after you do - obviously it will throw an error.

Franz
The file is probably empty right now, correct?
Franz
I don't understand? The class is loaded, no files are empty.
Rob
Could you please post the lines of code where the class is called for the first time (and thus autoloaded)?
Franz
A: 

Maybe you can try using spl_autoload_register instead. I've used that in an E_STRICT environment with out errors.. though technically what you're writing should work as well

Nodren
+1  A: 

The problem was that I was turning all my errors into exceptions with custom error handlers.

In STRICT mode, the class being included by autoload was giving a minor error about code usage. But this was being turned into an exception.

autoload ignores exceptions so that the next autoload (if multiple have been registered) can try to load the class.

Therefore the error in my class file was never shown, but prevented the class from existing, giving the mysterious error on line 0 problem.

Disabling my custom error handler meant PHP printed an error (which I can see) rather than throwing an exception (which gets suppressed by autoload), and then I could see the real cause of the problem and fix it.

Rob