php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66688 Direct invokation of a static method inside an abstract class
Submitted: 2014-02-10 18:51 UTC Modified: 2018-04-08 17:45 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: nikola at petkanski dot com Assigned:
Status: Suspended Package: Class/Object related
PHP Version: 5.4.25 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-02-10 18:51 UTC] nikola at petkanski dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5.abstract
---

Invoking static method of abstract class should be removed.

What interfaces are?
- A mean to ensure all implementation have the same methods implemented.

What is an abstract class?
- It is a interface that can also include some concrete methods.

Is it right for the developer to be able to invoke a static method of an interface?
- I think not.

The GoF teach us to rely on abstract classes and interfaces to hide differences between subclasses from clients.
- Interface defines an object’s use (protocol)
- Implementation defines particular policy

I don't think one should be able to call some abstract logic that is defined inside an abstract class, without even inheriting the class itself.

This post from the mailing list seem relevant:
- http://marc.info/?l=php-internals&m=114120699223033&w=2

Perhaps there are some reasons behind this behavior. However, the language evolves and I think it is time for this one to go.

Test script:
---------------
http://pastebin.com/a5bG6hww

Expected result:
----------------
It should display an error that one cannot invoke abstract class methods.

Actual result:
--------------
It just works, while it should not.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-08 17:45 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2018-04-08 17:45 UTC] cmb@php.net
This appears to be rather a feature request than a doc bug.

However, changing this behavior[1] would require the RFC
process[2] due to huge BC break.  Please go ahead and start it!
For the time being I'm suspending this ticket.

[1] <https://3v4l.org/QSTTv>
[2] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 22:01:31 2024 UTC