I've registered an autoloader (spl_autoload_register) and set a custom error handler (set_error_handler).
Next I have 3 classes: Class1, Class2 and Class3. Class2 extends Class1 but their methods getText() do not match. (Class1 expects a parameter of type Class3)
Including Class1 first and Class2 second gives me a fatal error "Class 'Class3' not found in ...". What I would expect is a strict warning. (If I do not include Class1 first everything is fine.)
index.php
<?php
class AutoLoader
{
public static function run ($className)
{
require(__DIR__."/".$className.".php");
}
}
spl_autoload_register(array('AutoLoader', "run"));
class ErrorHandler
{
public static function error ($errno, $errstr, $errfile, $errline)
{
echo 'error';
}
}
set_error_handler('ErrorHandler::error');
echo 'a';
require( __DIR__.'\Class1.php' );
echo 'b';
require( __DIR__.'\Class2.php' );
echo 'c';
?>
Class1.php
<?php
class Class1
{
public static function getText ($text=Class3::TEXT)
{
}
}
?>
Class2.php
<?php
class Class2 extends Class1
{
public static function getText ()
{
}
}
?>
Class3.php
<?php
class Class3
{
const TEXT = "text";
}
?>
With php 5.3.5 I get the expected result: aberrorc
With php 5.5.6 I get the fatal error: abFatal error...
A similar problem is discribed here set_error_handler function not calling autoload and here https://bugs.php.net/bug.php?id=54054 (Both try to autoload a class within the error-handler-function. The answers are about "compiling/execution", saying it is "not a bug". I'm in doubt about this, cause it's working in 5.3 and it's not exactly the same setting.)
How can I fix this issue without sorting out all strict-warnings in my scripts?