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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.