Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28692 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1688 invoked by uid 1010); 5 Apr 2007 16:24:24 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 1673 invoked from network); 5 Apr 2007 16:24:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Apr 2007 16:24:24 -0000 X-Host-Fingerprint: 193.171.131.245 teacheradsl245.eduhi.at Received: from [193.171.131.245] ([193.171.131.245:8694] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/9E-19248-6B225164 for ; Thu, 05 Apr 2007 12:24:23 -0400 Message-ID: <64.9E.19248.6B225164@pb1.pair.com> To: internals@lists.php.net Date: Thu, 05 Apr 2007 18:36:11 +0200 User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 193.171.131.245 Subject: Re: abstract static function From: jakob.buchgraber@gmail.com (Jakob Buchgraber) 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: > > 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