我如何实例化一个具有私有构造函数的类.
我不想在类中使用任何函数来创建自己的实例.
Ex类是:
- class Test extends Test2 implements Test3 {
- private function __construct () {
- }
- function doDisplay() {
- }
- function Docall() {
- }
- }
您无法从构造函数为私有的类(超出教学大纲)实例化对象.
如果您打算使用它的功能,那么您应该将它们作为静态使用它们来满足您的需求.确保该功能是公开的.
例如:
- <?PHP
- class something
- {
- private function __construct()
- {
- echo "something";
- }
- public static function display($msg)
- {
- echo $msg;
- }
- }
- something::display("Testing...");
- ?>
请参阅工作示例:http://codepad.org/VoYeyk8W