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

 ID:                 53081
 Comment by:         giorgio dot liscio at email dot it
 Reported by:        giorgio dot liscio at email dot it
 Summary:            why you should bring back abstract static methods
 Status:             Bogus
 Type:               Feature/Change Request
 Package:            Class/Object related
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

i know, but:



abstract class cA

{

      //static function A(){self::B();} error, undefined method

      static function A(){static::B();} // good

      abstract static function B();

}



class cB extends cA

{

    static function B(){echo "ok";}

}



cB::A();


Previous Comments:
------------------------------------------------------------------------
[2010-10-16 08:27:01] ras...@php.net

No, you are calling a method in an abstract class.  The fundamental
characteristic 

of an abstract class is that you cannot call methods in them.

------------------------------------------------------------------------
[2010-10-16 08:15:46] giorgio dot liscio at email dot it

hi Rasmus, what an honor!



can you please give me some example code?



you are saying that self:: points to an abstract not-implemented
method?



for example:



abstract class cA

{

      static function A(){self::B();}

      abstract static function B();

}





in this case can be thrown an error, but using static:: the call refers
to the called class method, not the declaring class



static function A(){static::B();}



so it can be re-enabled in this case, no?



in php static methods are really powerful unlike java's, c#'s, don't
limit them!



why interfaces allows static abstract methods? how self:: is resolved?

------------------------------------------------------------------------
[2010-10-16 07:21:47] ras...@php.net

Sorry, I re-read that explanation, that didn't make sense.  I meant to
say that 

methods in an abstract class require that any instance of that class
implement 

those methods, but static methods belong to the class, not an instance. 
You can't 

call methods from an abstract class, you can only call them in instances
of that 

class, but static methods by definition belong to the class, but since
you can't 

call methods in an abstract class you could never call these static
methods so 

there is no point in them being there.

------------------------------------------------------------------------
[2010-10-16 07:15:35] ras...@php.net

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.

------------------------------------------------------------------------
[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);

     }

}

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=53081


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

Reply via email to