Re: Traits and static methods
| From: | Simas Toleikis | Date: | Mon, 22 Nov 2010 12:47:18 +0000 |
| Subject: | Re: Traits and static methods | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-50410@lists.php.net to get a copy of this message | ||
Hi Sebastian,
This is not really a good example as the getInstance() method alone is
> not sufficient for a reusable implementation of the Singleton pattern.
>
Yes, it was just a pseudo-code and not a true singleton implementation.
> A trait for a reusable implementation of the Singleton pattern should
> look more like
> ...
> which of course does not work as traits are stateless and
>
Would it work if instance is saved inside a local static var like:
public static function getInstance() {
static $instance = NULL;
if (is_null($instance)) {
$instance = new self();
}
return $instance;
}
/Simas