note 80314 added to language.oop5.decon
| From: | nerdystudmuffin at gmail dot com | Date: | Wed, 09 Jan 2008 19:11:15 +0000 |
| Subject: | note 80314 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134979@lists.php.net to get a copy of this message | ||
Correction to the previous poster about non public constructors. If I wanted to implement Singleton
design pattern where I would only want one instance of the class I would want to prevent
instantiation of the class from outside of the class by making the constructor private. An example
follows:
class Foo {
private static $instance;
private __construct() {
// Do stuff
}
public static getInstance() {
if (!isset(self::$instance)) {
$c = __CLASS__;
$instance = new $c;
}
return self::$instance;
}
public function sayHello() {
echo "Hello World!!";
}
}
$bar = Foo::getInstance();
// Prints 'Hello World' on the screen.
$bar -> sayHello();
----
Server IP: 69.147.83.197
Probable Submitter: 159.182.173.20
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/80314
Del: integrated -- https://master.php.net/note/delete/80314/integrated
Del: useless -- https://master.php.net/note/delete/80314/useless
Del: bad code -- https://master.php.net/note/delete/80314/bad+code
Del: spam -- https://master.php.net/note/delete/80314/spam
Del: non-english -- https://master.php.net/note/delete/80314/non-english
Del: in docs -- https://master.php.net/note/delete/80314/in+docs
Del: other reasons-- https://master.php.net/note/delete/80314
Reject -- https://master.php.net/note/reject/80314
Search -- https://master.php.net/manage/user-notes.php