Created
May 15, 2017 09:23
-
-
Save jworksuk/e6c8ed1f8eda2012db8c228894da7866 to your computer and use it in GitHub Desktop.
Reminder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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