Marco.org

I’m : a programmer, writer, podcaster, geek, and coffee enthusiast.

Can PHP do this?

(new Whatever())->function();

It gives me a parse error and makes me do this instead:

$w = new Whatever(); $w->function();

But you can do this perfectly well:

$w->function()->otherFunction();

One hack is to define a function with the same name as the class that returns an instance:

function Whatever() { return new Whatever(); }
/* ... */
Whatever()->function()->otherFunction();

But that’s a hack.