Anonymous classes in PHP 7

Code
<?php

use Psr\Log\{AbstractLoggerLoggerInterfaceLoggerAwareInterface};

$logger = new class() extends AbstractLogger {
    public function 
log($level$message, array $context = array())
    {
        
$msg sprintf('[%s] %s'$level$message);
        
        if (
$context) {
            
$search array_keys($context);
            
array_walk($search, function(&$value$key) {
                
$value sprintf('{%s}'$value);
            });
            
$replace array_values($context);
        
            
$msg str_replace($search$replace$msg);
        }
        
        echo 
$msg PHP_EOL;
    }
};

$object = new class() implements LoggerAwareInterface {
    private 
$logger;
    
    public function 
setLogger(LoggerInterface $logger)
    {
        
$this->logger $logger;
    }
    
    public function 
run()
    {
        if (
null !== $this->logger) {
            
$this->logger->error('an error happened in {file}', array('file' => 'foo.php'));
            
$this->logger->notice('{reason} happened, but I work anyway', array('reason' => 'stuff'));
        }
        
        return 
0;
    }
};

$object->setLogger($logger);
$object->run();
Result
[error] an error happened in foo.php
[notice] stuff happened, but I work anyway
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8