Created
December 4, 2016 17:20
-
-
Save gorkamu/42e54f569b26e5639e437e08c94e0d53 to your computer and use it in GitHub Desktop.
Ejemplo de herencia de variables en las funciones anónimas
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 | |
$mensaje = 'hola'; | |
// Sin "use" | |
$ejemplo = function () { | |
var_dump($mensaje); | |
}; | |
$ejemplo(); // Notice: Undefined variable: message in /example.php on line 7 | |
// Heredar $mensaje | |
$ejemplo = function () use ($mensaje) { | |
var_dump($mensaje); | |
}; | |
$ejemplo(); // hola |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment