Skip to content

Instantly share code, notes, and snippets.

@jworksuk
Created May 15, 2017 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jworksuk/e6c8ed1f8eda2012db8c228894da7866 to your computer and use it in GitHub Desktop.
Save jworksuk/e6c8ed1f8eda2012db8c228894da7866 to your computer and use it in GitHub Desktop.
Reminder
<?php
function wrapFunction(callable $func, array $params)
{
try {
$data = $func(...$params);
} catch (\Exception $e) {
$data = false;
}
return $data;
}
class Acme
{
public function test(int $id, string $name)
{
if ($id == 0) {
throw new Exception('What is up guys!');
}
return [
'id' => $id,
'name' => $name,
];
}
}
$class = new Acme;
$result1 = wrapFunction([$class, 'test'], [1,'Jesse']);
$result2 = wrapFunction([$class, 'test'], [0,'fail']);
var_dump($result1);
var_dump($result2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment