Static initializer

  Status: implemented, (2004/09/20 11:41:34)
  • Created: 2003-11-16 19:06:40+0100
  • Categories: <core>
  • Author: friebe

Scope of Change

Make classes have a static initializer to be able to initialize static member variables to a class.


Rationale

Static members of a class can only be initialized to scalars in a class definition.

Functionality

The static initializer will, if existant for a class, be called by uses().

Implementation:

  // Call static initializer
if (is_callable(array($class, '__static'))) {
call_user_func
(array($class, '__static'));
}

Example:

  final class Console {
public static $out, $err= NULL;

public static function __static() {
self::
$out= new OutputStream(STDOUT);
self::
$err= new OutputStream(STDERR);
}
}

Dependencies

PHP5 XP2 Changes to uses() functionality.

Related documents

http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#39245 http://www.developer.com/java/other/article.php/2238491

Comments

- friebe, Sun Nov 16 19:09:43 CET 2003 Do some benchmarking on how much this will slow down uses() <EOF>


Table of contents