Is there anything wrong with taking immediate actions in constructors?
- by pestaa
I have classes like this one:
class SomeObject
{
public function __construct($param1, $param2)
{
$this->process($param1, $param2);
}
...
}
So I can instantly "call" it as some sort of global function just like
new SomeObject($arg1, $arg2);
which has the benefits of
staying concise,
being easy to understand,
but might break unwritten rules of semantics by not waiting till a method is called.
Should I continue to feel bad because of a bad practice, or there's really nothing to worry about?
Clarification:
I do want an instance of the class.
I do use internal methods of the class only.
I initialize the object in the constructor, but call the "important" action-taker methods too.
I am selfish in the light of these sentences.