これはなぜ機能しないのですか?それぞれのインスタンスを単純に参照する必要はありませんか?2つのシングルトンクラスを互いに参照できますか?
class foo {
private static $instance;
private function __construct() {
$test = bar::get_instance();
}
public static function get_instance() {
if (empty(self::$instance)) {
self::$instance = new foo();
}
return self::$instance;
}
}
class bar {
private static $instance;
public function __construct() {
$test = foo::get_instance();
}
public static function get_instance() {
if (empty(self::$instance)) {
self::$instance = new bar();
}
return self::$instance;
}
}
$test = foo::get_instance();
ありがとう、私はそれを得る、意味をなさない。 – pmm
@pmmmm:この回答があなたの問題を解決する場合、この回答のスコアの下にあるチェックボックスの輪郭にチェックを入れて[受け入れられるとマークする](http://stackoverflow.com/faq#howtoask)。それは、同じ問題があなたを助けてくれた人たちを見せてくれるのに役立ちます。 – ircmaxell
これは競合状態ではありません。リンク先の記事を読んでください。 –