Traits are the best thing to happen to PHP
If you haven't made good use of traits you should start using them. There really couldn't be a better example of why to use traits than for this alone:
trait Singleton
{
private static $_instance;
public static function getInstance() {
if (!self::$_instance instanceof self) {
self::$_instance = new self;
}
return self::$_instance;
}
}
class Class_1
{
use Singleton;
}
class Class_2
{
use Singleton;
}
That's at least 6 lines of code you never have to repeat to make a class Singleton...
Written by Ashley Banks
Related protips
1 Response
Traits++
Singleton--
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Related Tags
#php
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#