|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-12-02 11:09 UTC] schaa101 at tech dot nhl dot nl
Description: ------------ When you use 2 singletons, the second singeleton also returns the instance of the first. If you change the name of the variables, that store the instance of the singleton class, inside the singletons and make them both unique, the problem is solved though. Reproduce code: --------------- http://klaas.fiskaaf.com/singleton-bug.rar or try http://klaas.fiskaaf.com/singleton-bug.zip Expected result: ---------------- Singleton1 - Singleton1 Singleton2 - Singleton2 Actual result: -------------- Singleton1 - Singleton1 Singleton1 - Singleton2 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 05:00:02 2025 UTC |
<?php class Singleton1 { private $instance = null; private function __Construct() { } public function & GetInstance() { if( $this->instance == null ) $this->instance = new Singleton1(); return $this->instance; } public function Write( $message ) { print "Singleton1 - " . $message; } } class Singleton2 { private $instance = null; private function __Construct() { } public function & GetInstance() { if( $this->instance == null ) $this->instance = new Singleton2(); return $this->instance; } public function Write( $message ) { print "Singleton2 - " . $message; } } class Main { public function __Construct() { Singleton1::GetInstance()->Write( "Singleton1" ); echo "<br/>"; Singleton2::GetInstance()->Write( "Singleton2" ); } } new Main(); ?>