php.net |  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
Votes:17
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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;
     }
}


Patches

Pull Requests

History

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.
3. WONTFIX
 [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. :: https://bugs.php.net/bug.php?id=53081

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