时间:2021-07-01 10:21:17 帮助过:3人阅读
/*基类*/class BaseModel{ private static $instance = null; public static function instance() { if (empty(self::$instance)) { self::$instance = new self(); } return self::$instance; }}
/*商品类*/class GoodModel extends BaseModel{ public function getInfoById($goodId){ return array( 'id'=>$goodId, 'name'=>'小苹果', 'logo'=>'http://t3.qlogo.cn/mbloghead/65518bb9e5287fcd5864/180' ); }}################################################################$good = GoodModel::instance();var_dump($good);
object(BaseModel)#1 (0) {}
/*基类*/class BaseModel{ private static $instance = null; public static function instance() { if (empty(self::$instance)) { self::$instance = new static(); } return self::$instance; }}
object(GoodModel)#1 (0) {}
class BaseModel{ private static $instance = null; public static function instance() { if (empty(self::$instance)) { $className = get_called_class(); self::$instance = new $className(); } return self::$instance; }}