note 67958 added to language.oop5.patterns

From: Date: Fri, 07 Jul 2006 16:59:06 +0000
Subject: note 67958 added to language.oop5.patterns
Groups: php.notes 
Request: Send a blank email to php-notes+get-114566@lists.php.net to get a copy of this message
I don't know if it's useful has a singleton that is a singleton only inside a script. By example, having the following scripts: <?php //index.php require_once("Singleton.php"); $p = Singleton::getInstance(); $s = Singleton::getInstance(); ?> <?php //Singleton.php class Singleton { private static $instance; private function __construct() { } public static function getInstance() { if(!isset(self::$instance)) { echo 'creating singleton'; self::$instance = new self; } return self::$instance; } } ?> Calls to index.php always returns the message 'creating singleton', so a new instance of the class is created for each call to index.php; and this is not the behaviour that I'd expect. Best regards, Ubaldo ---- Server IP: 66.163.161.117 Probable Submitter: 200.105.149.82 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.patterns.php Edit -- http://master.php.net/note/edit/67958 Del: integrated -- http://master.php.net/note/delete/67958/integrated Del: useless -- http://master.php.net/note/delete/67958/useless Del: bad code -- http://master.php.net/note/delete/67958/bad+code Del: spam -- http://master.php.net/note/delete/67958/spam Del: non-english -- http://master.php.net/note/delete/67958/non-english Del: in docs -- http://master.php.net/note/delete/67958/in+docs Del: other reasons-- http://master.php.net/note/delete/67958 Reject -- http://master.php.net/note/reject/67958 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114566) next »