Samodzielne wykonywanie funkcji w PHP5. 3?
Próbowałem pożyczyć kilka paradygmatów programowania z JS do PHP (tak dla Zabawy). Jest jakiś sposób:
$a = (function(){
return 'a';
})();
Myślałem, że z kombinacją {[3] } może to być dobry sposób na ukrycie zmiennych w stylu JS
$a = (function(){
$hidden = 'a';
return function($new) use (&$hidden){
$hidden = $new;
return $hidden;
};
})();
Teraz muszę zrobić:
$temp = function(){....};
$a = $temp();
To wydaje się bezcelowe... 32
Author: AriehGlazer, 2010-10-05
1 answers
Funkcja wywołania łańcucha, np. {[3] } jest w dyskusji dla PHP5. 4. do tego czasu użyj call_user_func
:
$a = call_user_func(function(){
$hidden = 'a';
return function($new) use (&$hidden){
$hidden = $new;
return $hidden;
};
});
$a('foo');
var_dump($a);
Daje:
object(Closure)#2 (2) {
["static"]=>
array(1) {
["hidden"]=>
string(3) "foo"
}
["parameter"]=>
array(1) {
["$new"]=>
string(10) "<required>"
}
}
Począwszy od PHP7, możesz natychmiast wykonywać anonimowe funkcje, takie jak:
(function() { echo 123; })(); // will print 123
54
Author: Gordon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-29 06:11:47
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-29 06:11:47