Jingcheng Zhang wrote:
Hi internals,
   I used to use abstract static function prior to php 5.2, because when I
consider static class as a singleton, I can use abstract static function to
delay the implementation of some methods to the derived classes. This
happens, for example, when I declare a parent dispatcher, and extend it into
two classes - action dispatcher and ajax dispatcher - and declare them
static as I want to keep them a singleton because they are just application
models, not domain models:

<?php
abstract class Dispatcher {
   abstract public static function dispatch();
   public static function exampleMethod() {
       ...
   }
}
final class ActionDispatcher {
   public static function dispatch() {
       parent::exampleMethod();
       // other code...
   }
}
final class AjaxDispatcher {
   public static function dispatch() {
       parent::exampleMethod();
       // other code...
   }
}
?>
   Unfortunately, since php 5.2, although it does still allow declaring
static methods in an interface, it simply generates a message when declaring
abstract static functions with error_reporting set to E_ALL | E_STRICT.
   PHP is a dynamic language, not static as C++ and Java. So, why not allow
abstract static functions? It is also a good way to support singleton
natively.
   Waiting for explanations. Thanks :)


Maybe because it doesn't make sense to declare an abstract static method as a static method always belongs to a class. So if you declare it as abstract it needs to be overridden and wouldn't belong to the class anymore as each subclass has it's own implementation.

So from an OO point of view this would be a complete nonsense.

Cheers,
Jay

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to