Req #54003 [Opn->Csd]: re-enable abstract static methods

From: Date: Wed, 06 May 2015 16:53:40 +0000
Subject: Req #54003 [Opn->Csd]: re-enable abstract static methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192524@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54003&edit=1

 ID:                 54003
 Updated by:         nikic@php.net
 Reported by:        giorgio dot liscio at email dot it
 Summary:            re-enable abstract static methods
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
 Package:            Class/Object related
 PHP Version:        5.3.5
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

This no longer throws the strict standard warning in PHP 7.


Previous Comments:
------------------------------------------------------------------------
[2013-01-08 23:31:02] 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.

------------------------------------------------------------------------
[2012-10-26 16:26:29] dagguh at gmail dot com

1. Don't use LSB next time.
2. Use normal inheritance instead.
3. WONTFIX

------------------------------------------------------------------------
[2012-03-06 04:19:14] 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.

------------------------------------------------------------------------
[2011-02-13 00:14:32] 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;
     }
}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=54003&edit=1


Thread (5 messages)

« previous php.bugs (#192524) next »