Php 带异常变量的重定向
我有以下(测试)设置: web.phpPhp 带异常变量的重定向,php,session,laravel-5.3,Php,Session,Laravel 5.3,我有以下(测试)设置: web.php Route::get("test/test","TestController@test"); Route::get("test/numeric","TestController@numeric"); Route::get("forbidden", "TestController@exception") use \Symfony\Component\HttpKernel\Exception\HTTPException; public class Test
Route::get("test/test","TestController@test");
Route::get("test/numeric","TestController@numeric");
Route::get("forbidden", "TestController@exception")
use \Symfony\Component\HttpKernel\Exception\HTTPException;
public class TestController {
public function test() {
return redirect()->to("/forbidden")->with("exception",new HttpException(403));
}
public function numeric() {
return redirect()->to("/forbidden")->with("exception",403);
}
public function exception() {
if (\Session::get("exception") instanceof \Throwable) {
throw \Session::get("exception"); //Let the default handler handle it.
} else if (is_numeric(\Session::get("exception"))) {
throw new HttpException(\Session::get("exception"));
} else {
return "Empty exception";
}
}
}
TestController.php
Route::get("test/test","TestController@test");
Route::get("test/numeric","TestController@numeric");
Route::get("forbidden", "TestController@exception")
use \Symfony\Component\HttpKernel\Exception\HTTPException;
public class TestController {
public function test() {
return redirect()->to("/forbidden")->with("exception",new HttpException(403));
}
public function numeric() {
return redirect()->to("/forbidden")->with("exception",403);
}
public function exception() {
if (\Session::get("exception") instanceof \Throwable) {
throw \Session::get("exception"); //Let the default handler handle it.
} else if (is_numeric(\Session::get("exception"))) {
throw new HttpException(\Session::get("exception"));
} else {
return "Empty exception";
}
}
}
当我导航到/test/test
时,总会出现“空异常”。
但是,/test/numeric
正常显示异常。此外,我在两种情况下都检查了会话的内容,在第一种情况下,根本不传递exception对象
我是不是漏掉了什么明显的东西 在深入挖掘之后,我意识到由于异常堆栈跟踪,这是不可能做到的。有很多函数将闭包作为参数,因此异常堆栈跟踪是不可序列化的。Laravel似乎悄悄地从会话中删除任何不可序列化的变量