You cannot call instanciation and a method in one statement ... But the way to βcheatβ is to create a function that returns an instance of the class you are working with - and then call a method for this function that returns an object:
function my_function() {
return new MyClass();
}
my_function()->myMethod();
And in such a situation there is a useful trick: class names and function names do not belong to the same namespace, which means you can have a class and function that have the same name : they do not conflict!
So, you can create a function that has the same name as your class, initializes it and returns this instance:
class MyClass {
public function myMethod() {
echo 'glop';
}
}
function MyClass() {
return new MyClass();
}
MyClass()->myMethod();
(, , - ;-))