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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 + 48 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Sat Sep 19 16:01:24 2020 UTC