单例模式单例模式有什么作用?控制实例数量,节省系统资源。表演代码number;}/***@paramint$number*/publicfunctionsetNumber(int$number):void{$this->number=$number;}}$firstControl=NumberControl::getInstance();$firstControl->setNumber(1);echo$firstControl->getNumber()。PHP_EOL;//1$secondControl=NumberControl::getInstance();echo$secondControl->getNumber().PHP_EOL;//1$secondControl->setNumber(2);echo$firstControl->getNumber().PHP_EOL;//2echo$secondControl->getNumber().PHP_EOL;//2运行结果注意单例类只能有一个实例单例类必须是自己创建的唯一实例。单例类的构造函数应该是私有方法,以防止外部实例化。知识参考菜鸟教程|单例模式大菌说事:编程中的那些套路-浅谈单例模式
