is there a way to write a class that can be called like a function? I mean something like this:
class test{}
$test = new test;
$test();
I tried with the __call magic method but it can be used only when accessing in-existent methods on it. Maybe it can be done using SPL classes or interfaces?
$someclass()isn't descriptive. It does in no single way describe what you intend to do, to readers of your code. Function names should be descriptive, they should show you (and again, the readers of your code who don't know your intent, which might very well be you in a couple of months). So: think of what you want to do, and create a function for it.$test->GetFoo()or$test->CreateBar()show what you do in the function, without having to look at it.$test, in what state it needs to be, if it returns something and what, whether you can expect it to go wrong, and so on.