You are not logged in.
Pages: 1
to all you php5 gurus out there.
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?
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Well, you don't offer but a hint as to what's in "SomeClass", so I rolled my own. This works for me (no segfault):
$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()?
Offline
heh..thanks. I figured out my issue quite a while ago. I forgot to post that I had solved it on my own..
thanks though..
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..
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Pages: 1