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:


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

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

But that’s a hack.