rfc:static-classes

This is an old revision of the document!


Request for Comments: Static classes for PHP

  • Version: 0.1
  • Date: 2008-05-03
  • Author: Lars Strojny lstrojny@php.net
  • Status: in the works

Introduction

Static classes are a well known construct for utility classes or stateless abstraction. C# for example has an class System.Environment to access command line options, the current directory, the name of the machine where the program is running and so on. In PHP the current practice is to use an abstract class with static methods.

Syntax

<?php
static class StaticClass
{
    public static function staticMethod()
    {}
}
 
abstract static class AbstractStaticClass
{
    abstract static public static 
}

Object model rules

The following rules would apply for static classes:

  • Declared static classes may not have non-static members
  • Static methods in abstract static classes may not be called. They must be extended first
  • In static classes, abstract static methods are allowed again
  • Static classes may not have a constructor, destructor, dynamic interceptors or __toString()
  • Static classes may not extend non-static classes
  • The current behaviour of abstract classes/non-static classes with static members would not change. This is important for backwards compatibility

Code

rfc/static-classes.1209827437.txt.gz · Last modified: 2017/09/22 13:28 (external edit)