dongneng5383
dongneng5383
2014-01-30 16:06

将析构函数声明为私有是否可以?

  • oop
  • php

Some of my classes declare their constructors as private because an object of such class is only allowed to be created by a static method of the class. May I also declare destructors of such classes as private to keep it symmetric, is it safe?

EDIT: Ok, seems like this is simply not possible:

Fatal error: Call to private AClass::__destruct() from context '' in /script on line 0

(the context is empty and there's no such thing as line 0). For some reason I used to think that the PHP runtime is almighty and can destruct anything it wants.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐