WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML


 

PHP 7 Anonymous Classes


Now in Php 7 anonymous class used in place full class defination

Example


<?php
   interface messanger {
      public function log(string $msg);
   }

   class Application {
      private $logger;

      public function getLogger(): messanger {
         return $this->logger;
      }

      public function setLogger(messanger $logger) {
         $this->logger = $logger;
      }  
   }

   $app = new Application;
   $app->setLogger(new class implements messanger {
      public function log(string $msg) {
         print($msg);
      }
   });

   $app->getLogger()->log(This is  programming");
?>

The following output will be given:

This is  programming
Run example »