3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface Writer { public function write($message); } class Logger { private $writer; public function __construct(Writer $writer) { $this->writer = $writer; } public function log($message) { $this->writer->write($message); } } $logger = new Logger(new Writer() { public function write($message) { echo "Logged using an anonymous writer: {$message}" . PHP_EOL; } }); $logger->log('My message'); // outputs “Logged using an anonymous writer: My message”
based on o90dW
Output for 7.0.0
Parse error: syntax error, unexpected '{', expecting ',' or ')' in /in/jeZ09 on line 18
Process exited with code 255.
Output for 5.3.20 - 5.6.16
Parse error: syntax error, unexpected '{' in /in/jeZ09 on line 18
Process exited with code 255.