Correction status:Uncorrected
Teacher's comments:
1.编程: 单例模式:
<?php //1.编程: 单例模式 echo '//1.编程: 单例模式','<hr>'; class Student { //private $name; //private $age; private static $instance = null; //private 外部就没办法实例化了 private function __construct() { //$this->name = $name; //$this->age = $age; } //克隆方法私有化,外部也就无法访问了 private function __clone() { // TODO: Implement __clone() method. } //外部仅通过公共的静态方法创建实例 public static function getInstance() { //检测当前类的属性是否已经保存了当前类的实例 if (self::$instance == null) { self::$instance == new self(); } //返回当前的实例 return self::$instance; } } $obj1 = Student::getInstance(); $obj2 = Student::getInstance(); var_dump($obj1,$obj2); echo '<br>'; var_dump($obj1 === $obj2); echo '<br><br>';
点击 "运行实例" 按钮查看在线实例
2.编程: MVC的实现原理: