Created
November 19, 2016 09:00
-
-
Save gorkamu/d8e34772b80210c1cae1069318b7a5f9 to your computer and use it in GitHub Desktop.
Ejemplo 1 de clase anónima
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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