扫码关注官方订阅号
IDE实例化对象后,输入对象名会自动提示对象包含的方法。可是如果对象是用单例模式实现的,代码提示就没有了。请问有办法显示么?
闭关修行中......
用new static,问题解决
/** * 静态方法,单例统一访问入口 */ static public function getInstance() { $name = get_called_class(); if (isset($name::$_instance) && !is_null($name::$_instance)) { $_instance=$name::$_instance; }else{ $_instance=$name::$_instance = new static(); } return $_instance; }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
用new static,问题解决