abstract static function

From: Date: Thu, 05 Apr 2007 03:32:06 +0000
Subject: abstract static function
Groups: php.internals 
Request: Send a blank email to internals+get-28678@lists.php.net to get a copy of this message
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 :) -- Best regards, Jingcheng Zhang Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University P.R.China

« previous php.internals (#28678) next »