Anonymous classes

Anonymous classes are useful for simple one-off objects. With anonymous classes you can define a class and instantiate an object inline.

<?php
 /**
 Anonymous classes
 */ 
 $anonymousClassObject = new class {
     public function test() {
         return "PHPCodez";
     }
 };
 echo $anonymousClassObject->test();

Leave a Reply

Your email address will not be published. Required fields are marked *