Skip to content

Instantly share code, notes, and snippets.

@yehchge
Created March 31, 2019 06:48
Show Gist options
  • Save yehchge/89e849783810f76b29c3c8739e37f397 to your computer and use it in GitHub Desktop.
Save yehchge/89e849783810f76b29c3c8739e37f397 to your computer and use it in GitHub Desktop.
<?php
/**
* @desc decorator
*/
function save_db($str){
$wrap_func = function() use ($str) {
echo "run wrap_func".PHP_EOL;
echo "string = $str".PHP_EOL;
};
db_trans($wrap_func);
}
function save_table($str){
$wrap_func = function() use ($str) {
echo "run wrap".PHP_EOL;
echo $str.PHP_EOL;
};
db_trans($wrap_func);
}
function db_trans($method){
try{
echo "run db_trans".PHP_EOL;
$method();
}catch(Exception $e){
echo $e->getMessage();
}
}
$str = "John,Mary,David";
save_db($str);
save_table($str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment