note 65755 added to language.oop5.patterns
| From: | php-general at lists dot php dot net | Date: | Sun, 07 May 2006 17:55:25 +0000 |
| Subject: | note 65755 added to language.oop5.patterns | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110764@lists.php.net to get a copy of this message | ||
I have founded an additional way to use singleton, which made the __CLASS__ define in this function
unneeded. Just by using new self; Im not sure if this is reducing the parsetime.
<?php
class Example {
private static $instance;
public static function getInstance() {
if (!isset (self::$instance)) {
self::$instance = new self;
}
return self::$instance;
}
public function printString() {
return "I need to be printed.";
}
}
$foo = Example::getInstance();
print $foo->printString();
?>
----
Server IP: 83.137.20.120
Probable Submitter: 213.93.51.125
----
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/65755
Del: integrated -- http://master.php.net/note/delete/65755/integrated
Del: useless -- http://master.php.net/note/delete/65755/useless
Del: bad code -- http://master.php.net/note/delete/65755/bad+code
Del: spam -- http://master.php.net/note/delete/65755/spam
Del: non-english -- http://master.php.net/note/delete/65755/non-english
Del: in docs -- http://master.php.net/note/delete/65755/in+docs
Del: other reasons-- http://master.php.net/note/delete/65755
Reject -- http://master.php.net/note/reject/65755
Search -- http://master.php.net/manage/user-notes.php