note 118647 added to class.throwable
| From: | robert dot gol dot jr at gmail dot com | Date: | Thu, 14 Jan 2016 23:34:08 +0000 |
| Subject: | note 118647 added to class.throwable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204675@lists.php.net to get a copy of this message | ||
A sample of use. Throwing a fatal error in a Router:
<?php
class Router {
private static $routes = array();
private function __construct() {}
private function __clone() {}
public static function route($pattern, $callback) {
$pattern = '/^' . str_replace('/', '\/', $pattern) .
'$/';
self::$routes[$pattern] = $callback;
}
public static function execute($url) {
foreach (self::$routes as $pattern => $callback) {
if (preg_match($pattern, $url, $params)) {
array_shift($params);
return @call_user_func_array($callback, array_values($params));
}
}
throw new Exception("Err404", 404);
}
}
--_--_--_--_--_--_--_--_--_--_--_
<?php
Router::route("/(\w+)/?(\w+)?/?(\w+)?", function($param0, $param1='', $param2)
{
$params = func_get_args();
$model = ucwords(strtolower($params[0]));
try {
$model = new $model();
}catch (Throwable $t){
echo "Err404";
// echo $t->getMessage();
return;
} catch (Exception $e) {
echo "Err404";
return;
// echo $e->getMessage();
}
});
----
Server IP: 72.52.91.14
Probable Submitter: 152.232.219.237
----
Manual Page -- http://php.net/manual/en/class.throwable.php
Edit -- https://master.php.net/note/edit/118647
Del: integrated -- https://master.php.net/note/delete/118647/integrated
Del: useless -- https://master.php.net/note/delete/118647/useless
Del: bad code -- https://master.php.net/note/delete/118647/bad+code
Del: spam -- https://master.php.net/note/delete/118647/spam
Del: non-english -- https://master.php.net/note/delete/118647/non-english
Del: in docs -- https://master.php.net/note/delete/118647/in+docs
Del: other reasons-- https://master.php.net/note/delete/118647
Reject -- https://master.php.net/note/reject/118647
Search -- https://master.php.net/manage/user-notes.php