php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65809 interface, abstract static function
Submitted: 2013-10-02 10:58 UTC Modified: 2015-05-06 17:09 UTC
Votes:3
Avg. Score:1.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: spam at krol dot me Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3.15 OS:
Private report: No CVE-ID: None
 [2013-10-02 10:58 UTC] spam at krol dot me
Description:
------------
abstract static function in class isn't allowed,
but you can define static function in interface

This leads to funny inconsistency where you can create abstract static function using interfaces



Test script:
---------------
//abstract class A { abstract static function a(); } //invalid

interface I { static function i(); } //valid
abstract class B implements I {} //valid
//class C extends B{} // invalid
//Fatal error: Class C contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (I::i) in php shell code on line 1

class D extends B{
static function i(){echo "I have to be implemented"; }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-02 23:43 UTC] phpmpan at mpan dot pl
Abstract static methods are allowed. Abstract static *constructors* aren't.
 [2013-10-03 05:10 UTC] spam at krol dot me
-PHP Version: Irrelevant +PHP Version: 5.3.15
 [2013-10-03 05:10 UTC] spam at krol dot me
I changed PHP version as it IS revelant

According to this

http://php.net/manual/en/migration52.incompatible.php

Dropped abstract static class functions. Due to an oversight, PHP 5.0.x and 5.1.x allowed abstract static functions in classes. As of PHP 5.2.x, only interfaces can have them.
 [2013-10-03 05:21 UTC] spam at krol dot me
And use this test case. It don't make use of constructor

Test script:
---------------

abstract class A { abstract static function aa(); } //invalid
//Strict Standards: Static function A::aa() should not be abstract in php shell code on line 1

interface I { static function ii(); } //valid
abstract class B implements I {} //valid
//class C extends B{} // invalid
//Fatal error: Class C contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (I::i) in php shell code on line 1

class D extends B{
static function ii(){echo "I have to be implemented"; }
}
 [2013-10-03 06:49 UTC] phpmpan at mpan dot pl
I haven't noticed this, as the case doesn't produce an error, but only a E_STRICT level message. Ok, hence the report is now valid.

However, be aware that the issue was already discussed and I believe this message is the source of the patch that removed "abstract static" 7 years ago: http://marc.info/?l=php-internals&m=114120699223033&w=2
 [2015-05-06 17:09 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-05-06 17:09 UTC] nikic@php.net
The strict standards notice no longer exists in PHP 7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 18:01:30 2024 UTC