as for why no __construct? because it is a static class..it is never instantiated, just called. Hence, a constructor seemed silly..besides, you should avoid initializing other objects in a constructor. If a constructor fails while doing an object initialization, it could cause a race condition..
]]>$cat > test.php
<?php
class SomeClass {
public static function Eat() {
echo "Testn";
}
}
class Test {
private static $var;
public static function Init() {
self::$var=new SomeClass();
}
public static function Eat() {
self::$var->Eat();
}
}
Test::Init();
Test::Eat();
?>
^D
Output:
$ php test.php
Test
Also, why not use "function __construct()" instead of calling Init()?
]]>This is what I want to do:
class Test {
private static $var;
public static function Init() {
self::$var=new SomeClass();
}
public static function Eat() {
self::$var->Eat();
}
}
Test::Init();
Test::Eat();
It is no worky. :?
In fact, it causes a seg fault in one of the httpd daemon child processes. :shock:
[notice] child pid 3507 exit signal Segmentation fault (11)
I could try using a singleton, but I don't see why I should. Is this a shortcoming of the php5 class engine, or am I just doing it wrong?
Anyone?