Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created November 19, 2016 09:00
Show Gist options
  • Select an option

  • Save gorkamu/d8e34772b80210c1cae1069318b7a5f9 to your computer and use it in GitHub Desktop.

Select an option

Save gorkamu/d8e34772b80210c1cae1069318b7a5f9 to your computer and use it in GitHub Desktop.
Ejemplo 1 de clase anónima
<?php
class Util
{
private $logger;
public function setLogger(Logger $logger) {
$this->logger = $logger;
}
}
$util = new Util();
$util->setLogger(new Logger()); // Esto se hacía antes de PHP 7
$util->setLogger(new class { // Esto se hace a partir de PHP 7
public function __construct() {
echo "Soy un logger";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment