Is there a way to create an anonymous object in PHP

Can I work with code like:

new \Controllers\ServiceController()->fbdump(); 

so i don't need to create var to execute a single method?

+5
source share
1 answer

Yes, but you need to add a set of brackets, since -> has a higher priority than new :

 (new \Controllers\ServiceController)->fbdump(); 
+6
source

Source: https://habr.com/ru/post/1238741/


All Articles