Is it ok to declare destructor as private?
oop, php
Solution
In php the `__destruct` magic method must be `public`. The method will automatically be called externally to the instance. Declaring `__destruct` as `protected` or `private` will result in a warning and the magic method will not be called.
There's no symmetry necessary, as you should never explicitly call `__destruct`.
Problem
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.