Maison >développement back-end >tutoriel php >PHP类中动态方法和静态方法调用写法的不解,希望版主大大指导
PHP类中动态方法和静态方法调用写法的疑惑,希望版主大大指导
<?php<br />//error_reporting(0);<br />class A<br />{<br /> public $db='OK';<br /> private static $_instance;<br /> public static function getInstance()<br /> {<br /> if(!(self::$_instance instanceof self)){<br /> self::$_instance = new self;<br /> }<br /> return self::$_instance;<br /> }<br /> //维持find方法中this指针的写法不变<br /> public function find()<br /> {<br /> echo $this->db;<br /> }<br />}<br />class B extends A<br />{<br /> static function ex()<br /> {<br /> self::getInstance()->find(); <br /> }<br />}<br />$b=new B();<br />$b->find();<br />echo "<br>";<br />//第二种方法<br />B::ex();<br />?>