php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72993 abstract class with abstract static methods: valid or not?
Submitted: 2016-09-01 13:17 UTC Modified: 2016-09-01 22:27 UTC
From: mlocati at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.0.10 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mlocati at gmail dot com
New email:
PHP Version: OS:

 

 [2016-09-01 13:17 UTC] mlocati at gmail dot com
Description:
------------
Consider this code:

abstract class AbstractClass
{
    abstract public static function Method();
}
class ReadClass extends AbstractClass
{
    public static function Method()
    { }
}

is this valid? See for instance https://3v4l.org/nSsLg
- from PHP 5.0 to PHP 5.1: it was valid
- from PHP 5.2 to PHP 5.6: we have this warning:
Strict Standards: Static function AbstractClass::Method() should not be abstract
- from PHP 7.0: it is again valid

So... is this a wanted change? Or is it a bug in the 7.x series?

PS: I'm not saying that it shouldn't  be valid (indeed I'd prefer it's a legal approach)


Related bugs:

- https://bugs.php.net/bug.php?id=65809
There we just say that "The strict standards notice no longer exists in PHP 7", but does not say anything about the validity of abstract static methods in abstract classes

- https://bugs.php.net/bug.php?id=66688
There the reporter suggests to remove static methods from abstract classes (why PHP should force this? It's a philosophy approach, subject to developers mind, and the language shouldn't force developers to not do something - people who think it's wrong can simply avoid that approach)




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-01 13:24 UTC] mlocati at gmail dot com
-Summary: abstract class with static methods: valid or not? +Summary: abstract class with abstract static methods: valid or not?
 [2016-09-01 13:24 UTC] mlocati at gmail dot com
Renamed subject from

abstract class with static methods: valid or not?

to

abstract class with abstract static methods: valid or not?
 [2016-09-01 22:27 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-09-01 22:27 UTC] requinix@php.net
https://wiki.php.net/rfc/reclassify_e_strict#abstract_static_methods
Abstract static methods are now deliberately supported in classes for consistency with allowing static methods in interfaces.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 10:01:27 2024 UTC