Req #53081 [Opn->Bgs]: why you should bring back abstract static methods

From: Date: Sat, 16 Oct 2010 05:15:38 +0000
Subject: Req #53081 [Opn->Bgs]: why you should bring back abstract static methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155227@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53081&edit=1

 ID:                 53081
 Updated by:         rasmus@php.net
 Reported by:        giorgio dot liscio at email dot it
 Summary:            why you should bring back abstract static methods
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
 Package:            Class/Object related
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

A static method belongs to the class, not to an instance of that class
and since 
you can't have an instance of an abstract class, static methods make no
sense in 
abstract classes.  It is really that simple.


Previous Comments:
------------------------------------------------------------------------
[2010-10-16 06:58:55] giorgio dot liscio at email dot it

sorry, corrected code:

abstract class FSItem
{
      protected function __construct($path){}

      // random per-item singleton
      public static function getByPath($path)
      {
            if(static::isPathValid($path)) // here is the static method
call of classes. i want to check the path before instance it
                  return new static($path);
      }

      // abstract static method:
      abstract protected static function isPathValid($path);
}

class Dir extends FSItem
{
     //implementation:
     protected static function isPathValid($path)
     {
          return is_dir($path);
     }
}

class File extends FSItem
{
     //implementation:
     protected static function isPathValid($path)
     {
          return is_file($path);
     }
}

class Image extends File
{
     //implementation:
     protected static function isPathValid($path)
     {
          return (bool)getimagesize($path);
     }
}

------------------------------------------------------------------------
[2010-10-16 06:55:35] giorgio dot liscio at email dot it

Description:
------------
hi, i really can not understand why this was dropped, but imagine this
code

please read carefully and please examine my request before trash it

abstract class FSItem
{
      // abstract static method:
      abstract protected function isPathValid($path);

      protected function __construct($path){}

      // random per-item singleton
      public static function getByPath($path)
      {
            if(static::isPathValid($path)) // here is the static method
call of classes. i want to check the path before instance it
                  return new static($path);
      }
}

class Dir extends FSItem
{
     //implementation:
     protected function isPathValid($path)
     {
          return is_dir($path);
     }
}

class File extends FSItem
{
     //implementation:
     protected function isPathValid($path)
     {
          return is_file($path);
     }
}

class Image extends File
{
     //implementation:
     protected function isPathValid($path)
     {
          return (bool)getimagesize($path);
     }
}

php changelog says: 

Dropped abstract static class functions. Due to an oversight, PHP 5.0.x
and 5.1.x allowed abstract static functions in classes. As of PHP 5.2.x,
only interfaces can have them. 

oversight what? it is a logical error? technical limitation?

thank you



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



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


Thread (25 messages)

« previous php.bugs (#155227) next »