I still code with PHP 4 standards for compatibility. I have something like:
PHP Code:
class myClass {
// constructor
function myClass($some_var)
{
// sanity check $some_var
if ($some_var is NOT sane) {
$this = null; // destroy the class
return;
}
// do something with $some_var
...
}
}
I guess the alternative would be no actions in the constructor and then using some function called init() or something. Using an init() seemed like a useless step to me. The way I am doing it I can easily check the variable being assigned the object when I make the class using is_object().
Are there any potential pitfalls of destroying the object inside the constructor?