On 26 Sep 2012, at 22:13, Yves Goergen <nospam.l...@unclassified.de> wrote:

> I couldn't find out whether PHP supports static constructors, and how
> the syntax is. The web and the PHP manual don't mention it. So is it not
> supported? If it is, is there a PHP version restriction?

If you mean what C# calls a static constructor, no that does not exist in PHP, 
but you can fake it. Make sure the class is in it's own file, and you can 
initialise it like so…

<?php
  MyStaticClass::init();

  class MyStaticClass
  {
    static public function init()
    {
      // Do initialisation here
    }
  }

Then, when the class file is required the initialisation method will 
automatically be executed. However, I wouldn't encourage you to use static 
classes like this. The singleton pattern would be my recommendation.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to