Jump to content

abstarct static inconsistent error handling


jamInTheValleys

Recommended Posts

Hello,

 

If I have an index file with:

date_default_timezone_set('GMT');
error_reporting(E_ALL | E_STRICT); 

abstract class A {
    abstract public static function YesIReallyMeanAbstractStatic();
}

class B extends A {
    public static function YesIReallyMeanAbstractStatic() {
    }
}

 

This will not error.

 

However if I have:

 

date_default_timezone_set('GMT');
error_reporting(E_ALL | E_STRICT); 

require('class_a_in_a_different_file.php'); // Or use __autoload() to do the same.

class B extends A {
    public static function YesIReallyMeanAbstractStatic() {
    }
}

 

This will throw the error:

"Static function A::YesIReallyMeanAbstractStatic() should not be abstract"

 

I know abstract statics are debatable...

but it makes no sense to me for it to be allowed in the first example but disallowed in other.

 

So I was wondering if this is a bug? Or is there something else going on here?

 

I assume the parser is evaluating the included file and then throwing the error which doesn't happen if both classes are in the same file as they can then be evaluated altogether.

In the first example the error_reporting isn't set until after the evaluation of the file.

 

In the second example the error reporting is set by the first file and then the second file is evaluated, throwing the E_STRICT error.

Right, the parser is what throws the error, and the first document is fully parsed without the strict warning being thrown before it's executed and the error level is properly set.

 

Setting the error level in php.ini will "fix" this strange behavior.

 

-Dan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.