|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54003 re-enable abstract static methods
Submitted: 2011-02-13 00:14 UTC Modified: 2015-05-06 16:53 UTC
Avg. Score:4.6 ± 1.0
Reproduced:13 of 14 (92.9%)
Same Version:7 (53.8%)
Same OS:3 (23.1%)
From: giorgio dot liscio at email dot it Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: giorgio dot liscio at email dot it
New email:
PHP Version: OS:


 [2011-02-13 00:14 UTC] giorgio dot liscio at email dot it
hi, please read carefully my request before trash this

since static inheritance is now implemented in php, enabling this again can provide an awesome natural feature of the language

I talked with some php hackers, and they agree with me, but in past, I did not have good news about this:

I'm sure my example makes totally sense, and this should stay disabled only if there are technical limitations that do not matter with the good logic of my example

in practice, I can understand WONT FIX, but not BOGUS

abstract class AFileSystemItem
     public static function                getIfValid   ($fullPath)
          // i use static::isValid to get the method defined in the called class
          if(static::isValid($fullPath)) return new static($fullPath);
     protected function                    __construct  ($fp){}

     // i want to force real classes to implement a way to check a path before instance an object
     protected abstract static function    isValid      ($fullPath); // abstract declaration

class Dir extends AFileSystemItem
     protected static function             isValid      ($fullPath)  // implementation
         return is_dir($fullPath);

class File extends AFileSystemItem
     protected static function             isValid      ($fullPath)  // implementation
         return is_file($fullPath);

class Image extends File
     protected static function             isValid      ($fullPath)  // implementation with override
         if(parent::isValid($fullPath) AND (bool)getimagesize($fullPath)) return true; return false;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-06 04:19 UTC] cgili at yahoo dot com
Inheritance and method override is something really important on PHP, it's important to redefine not only the methods but also the parameters they take, for instance, you have a class Rectangle with a method called Area that calculates the area in m2 by requiring the height and width, now you want to create a Cube class extending the Rectangle class, and override the function Area to calculate the area in cubic meters, the formula is different and the parameters are 3, height, width and deep. It's the very "BASIC" definition of Class inheritance and Method Overriding.
 [2012-10-26 16:26 UTC] dagguh at gmail dot com
1. Don't use LSB next time.
2. Use normal inheritance instead.
 [2013-01-08 23:31 UTC] jon at langevin dot me
Valid issue, please consider.
In this related submission, Rasmus even agreed that the expected behavior is 
correct, but he didn't answer why PHP E_STRICT reports an error for abstract 
static method declaration. ::

When accessed via static::method(), this is a very valid programming approach.
 [2015-05-06 16:53 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-05-06 16:53 UTC]
This no longer throws the strict standard warning in PHP 7.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 22:01:26 2024 UTC