您的位置:首页 > 移动开发 > Objective-C

Fatal error: Call to private MyObject::__construct() from invalid context

2011-07-07 15:02 573 查看
问题: When creating a new object in PHP, I get the following error message:
Fatal error: Call to private MyObject::__construct() from invalid context

I just create the new object and do not try to call the constructor explicitly. Does anyone know what's going on? 解释:Your
MyObject
class has a protected or private constructor, which means that the class cannot be instantiated.
__construct()
functions are always called when an object is instantiated, so trying to do something like
$x = new MyObject()
will cause a fatal error with a private construction function. (If you do not specifically declare a
__construct()
function, the parent constructor will be called).Private constructors are often used in Singleton classes to prevent direct instantiation of an object. If it's not a class that you built, it might have a
getInstance()
function available (or something similar) to return an instance of itself.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐