Decorator Pattern replacement in functional PHP
<?php
$say_hello = function($name) {
return "hello, $name!\n";
};
$log_say = function ($func) {
return function ($name) use ($func){
echo "[ greeting mode enabled ]\n";
echo $func($name);
};
};
$logging_hello = function($name) use ($log_say, $say_hello) {
$l = $log_say($say_hello);
$l($name);
};
$logging_hello("John");