Is it possible to create static classes in PHP (like in C#)?

Posted by aleemb on Stack Overflow See other posts from Stack Overflow or by aleemb
Published on 2009-01-22T10:30:57Z Indexed on 2010/05/16 3:50 UTC
Read the original article Hit count: 390

Filed under:
|
|
|

I want to create a static class in PHP and have it behave like it does in C#, so

  1. Constructor is automatically called on the first call to the class
  2. No instantiation required

Something of this sort...

static class Hello {
    private static $greeting = 'Hello';

    private __construct() {
        $greeting .= ' There!';
    }

    public static greet(){
        echo $greeting;
    }
}

Hello::greet(); // Hello There!

© Stack Overflow or respective owner

Related posts about php

Related posts about oop