5.3 can be implemented before, but the code is more cumbersome, as follows:
Class Morder extends smodel{
protected static $handle; Single example handle
Private Function __construct () {
Something
}
/**
* The method of obtaining this type of singleton, public
*
* @return Morder
*/
public static function instance () {
if (self:: $handle) {
Return self:: $handle;
}
$class = __class__;
Self:: $handle = new $class ();
Return self:: $handle;
}
Otherthing
}
5.3 Add delay static bindings (This is a very awkward word)
The code is implemented as follows
Class Smodel {
/**
* Gets a single handle that returns an instance object of a specific model class
*/
Protected static function instance () {
if (static:: $handle) {
return static:: $handle;
}
$class = Get_called_class ();
Static:: $handle = new $class ();
return static:: $handle;
}
Parent class Something
}
Class Mgoods extends smodel{
/**
* The method of obtaining this type of singleton, public
* @return Mgoods
*/
public static function instance () {
return Parent::instance ();
}
protected static $handle; Single example handle
protected function __construct () {
Something
}
Otherthing
}
By modifying, the implementation code of the subclass is reduced in part, and is implemented by the parent class
To be honest, still very troublesome, if PHP oneself realizes singleton to be good.
http://www.bkjia.com/PHPjc/678027.html www.bkjia.com true http://www.bkjia.com/PHPjc/678027.html techarticle 5.3 can be implemented before, but the code is more cumbersome, as follows: Class Morder extends smodel{protected static $handle;//single Handle Private function __construct () {// Something}/** * get this class ...