In PHP can we do this?
function foo($c) {
$c;
echo 'done';
}
foo(function() {
echo 'test'
});
Such that the output will be:
testdone
This was my real problem :
function create_transaction($obj, $func, $errorMsg)
{
try {
$obj->transaction('START');
$func();
$obj->transaction('COMMIT');
} catch(Exception $e) {
$obj->transaction('ROLLBACK');
throw new exception($errorMsg . ' ---> ' . $e);
}
}
So i can call this function of create_transaction like this :
create_transaction($obj, function() {
echo 'test';
// this should be a database CRUD process
// to make it simple, i just put echo.
}, 'error');
create_transaction() will inserted the function code between the START and COMMIT.
But this way return an error :
Parse error: syntax error, unexpected T_FUNCTION
This error is in line where i wrote :
create_transaction($obj, function() { // Error here
$c()(in the body offoo).