YouTip LogoYouTip

Php Anonymous Classes

# PHP Anonymous Classes [![Image 3: PHP 7 New Features](#) PHP 7 New Features](#) PHP 7 supports instantiating an anonymous class via **new class**, which can be used as a replacement for a "use-and-dispose" full class definition. ### Example ## Example logger; } public function setLogger(Logger $logger) { $this->logger = $logger; } } $app = new Application; // Using new class to create an anonymous class $app->setLogger(new class implements Logger { public function log(string $msg) { print($msg); } }); $app->getLogger()->log("My first log"); ?> The output of the above program is: My first log * * PHP 7 New Features](#)
← R Data TypesR Comments β†’