Skip to content

Static initializer #2

@thekid

Description

@thekid

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:

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

Example:

<?php
  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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions