With a new feature in PHP 5.4, we can access a class member on the same line as instantiating the class.
// Instead of $obj = new myClass(); $obj->myMethod(); // PHP 5.4 allows $obj = (new myclass())->myMethod();
I have a class which doesn't need the object (variable) from the instantiated class, because the class being instantiated is an exit controller and just "does some things" then halts the entire system.
I'd like to know if accessing a class member at the time of instantiating the class is ok without using the variable.
// With variable (standard practice) $obj = (new myclass())->myMethod(); // Without using the variable (new myclass())->myMethod();
Both code options work perfectly fine, but I've not seen this done without using the variable to store the object. And sometimes something can be done incorrectly from a technical or "best practise" standpoint but still work because of some unrelated reason (or luck etc).
So I would like to know if this is acceptable usage?
Or are there any "technical" reasons it shouldn't be done like this?