Tested using fresh Laravel 5.2.31
When printing 'request' using print_r / var_dump inside a controller, the browser hangs.
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class Test extends Controller
{
public function test(Request $request)
{
print_r($request);
}
}
Route
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::match(array('get','post'), '/test', 'Test@test')->name('test');
View
<!DOCTYPE html>
<html>
<head>
<title>Laravel</title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
<style>
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
width: 100%;
display: table;
font-weight: 100;
font-family: 'Lato';
}
.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}
.content {
text-align: center;
display: inline-block;
}
.title {
font-size: 96px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Laravel 5</div>
</div>
</div>
<form method="post" action="test">
{!! csrf_field() !!}
<input type="submit" value="export">
</form>
</body>
</html>
I somehow managed to stop it from loading.. Here's the page content. The page is much longer but I cannot paste all the text here
testIlluminate\Http\Request Object ( [json:protected] => [convertedFiles:protected] => [userResolver:protected] => Closure Object ( [static] => Array ( [app] => Illuminate\Foundation\Application Object ( [basePath:protected] => D:\workspace\php\htdocs_web\tesbug [hasBeenBootstrapped:protected] => 1 [booted:protected] => 1 [bootingCallbacks:protected] => Array ( ) [bootedCallbacks:protected] => Array ( [0] => Closure Object ( [static] => Array ( [router] => Illuminate\Routing\Router Object ( [events:protected] => Illuminate\Events\Dispatcher Object ( [container:protected] => Illuminate\Foundation\Application Object _RECURSION_ [listeners:protected] => Array ( [App\Events\SomeEvent] => Array ( [0] => Array ( [0] => Closure Object ( [static] => Array ( [listener] => App\Listeners\EventListener [container] => Illuminate\Foundation\Application Object _RECURSION_ ) [this] => Illuminate\Events\Dispatcher Object _RECURSION_ ) ) ) ) [wildcards:protected] => Array ( ) [sorted:protected] => Array ( [Illuminate\Events\EventServiceProvider] => Array ( ) [Illuminate\Routing\RoutingServiceProvider] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\DetectEnvironment] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\DetectEnvironment] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\LoadConfiguration] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\LoadConfiguration] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\ConfigureLogging] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\ConfigureLogging] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\HandleExceptions] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\HandleExceptions] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\RegisterFacades] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\RegisterFacades] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\RegisterProviders] => Array ( ) [Illuminate\Auth\AuthServiceProvider] => Array ( ) [Illuminate\Cookie\CookieServiceProvider] => Array ( ) [Illuminate\Database\DatabaseServiceProvider] => Array ( ) [Illuminate\Encryption\EncryptionServiceProvider] => Array ( ) [Illuminate\Filesystem\FilesystemServiceProvider] => Array ( ) [Illuminate\Foundation\Providers\FoundationServiceProvider] => Array ( ) [Illuminate\Pagination\PaginationServiceProvider] => Array ( ) [Illuminate\Session\SessionServiceProvider] => Array ( ) [Illuminate\View\ViewServiceProvider] => Array ( ) [App\Providers\AppServiceProvider] => Array ( ) [App\Providers\AuthServiceProvider] => Array ( ) [App\Providers\EventServiceProvider] => Array ( ) [App\Providers\RouteServiceProvider] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\RegisterProviders] => Array ( ) [bootstrapping: Illuminate\Foundation\Bootstrap\BootProviders] => Array ( ) [bootstrapped: Illuminate\Foundation\Bootstrap\BootProviders] => Array ( ) [Illuminate\Routing\Events\RouteMatched] => Array ( ) ) [firing:protected] => Array ( ) [queueResolver:protected] => Closure Object ( [static] => Array ( [app] => Illuminate\Foundation\Application Object _RECURSION_ ) [this] => Illuminate\Events\EventServiceProvider Object ( [app:protected] => Illuminate\Foundation\Application Object _RECURSION_ [defer:protected] => ) ) ) [container:protected] => Illuminate\Foundation\Application Object _RECURSION_ [routes:protected] => Illuminate\Routing\RouteCollection Object ( [routes:protected] => Array ( [GET] => Array ( [/] => Illuminate\Routing\Route Object ( [uri:protected] => / [methods:protected] => Array ( [0] => GET [1] => HEAD ) [action:protected] => Array ( [middleware] => web [uses] => Closure Object ( [this] => App\Providers\RouteServiceProvider Object ( [namespace:protected] => App\Http\Controllers [app:protected] => Illuminate\Foundation\Application Object _RECURSION_ [defer:protected] => ) ) [namespace] => App\Http\Controllers [prefix] => [where] => Array ( ) ) [defaults:protected] => Array ( ) [wheres:protected] => Array ( ) [parameters:protected] => [parameterNames:protected] => [compiled:protected] => [router:protected] => Illuminate\Routing\Router Object _RECURSION_ [container:protected] => Illuminate\Foundation\Application Object _RECURSION_ ) [test] => Illuminate\Routing\Route Object ( [uri:protected] => test [methods:protected] => Array ( [0] => GET [1] => POST [2] => HEAD ) [action:protected] => Array ( [middleware] => web [uses] => App\Http\Controllers\Test@test [controller] => App\Http\Controllers\Test@test [namespace] => App\Http\Controllers [prefix] => [where] => Array ( ) [as] => test ) [defaults:protected] => Array ( ) [wheres:protected] => Array ( ) [parameters:protected] => Array ( ) [parameterNames:protected] => Array ( ) [compiled:protected] => Symfony\Component\Routing\CompiledRoute Object ( [variables:Symfony\Component\Routing\CompiledRoute:private] => Array ( ) [tokens:Symfony\Component\Routing\CompiledRoute:private] => Array ( [0] => Array ( [0] => text [1] => /test ) ) [staticPrefix:Symfony\Component\Routing\CompiledRoute:private] => /test [regex:Symfony\Component\Routing\CompiledRoute:private] => #^/test$#s [pathVariables:Symfony\Component\Routing\CompiledRoute:private] => Array ( ) [hostVariables:Symfony\Component\Routing\CompiledRoute:private] => Array ( ) [hostRegex:Symfony\Component\Routing\CompiledRoute:private] => [hostTokens:Symfony\Component\Routing\CompiledRoute:private] => Array ( ) ) [router:protected] => Illuminate\Routing\Router Object _RECURSION_ [container:protected] => Illuminate\Foundation\Application Object _RECURSION_ ) ) [HEAD] => Array ( [/] => Illuminate\Routing\Route Object ( [uri:protected] => / [methods:protected] => Array ( [0] => GET [1] => HEAD ) [action:protected] => Array ( [middleware] => web [uses] => Closure Object ( [this] => App\Providers\RouteServiceProvider Object ( [namespace:protected] => App\Http\Controllers [app:protected] => Illuminate\Foundation\Application Object _RECURSION_ [defer:protected] => ) ) [namespace] => App\Http\Controllers [prefix] => [where] => Array ( ) ) [defaults:protected] => Array ( ) [wheres:protected] => Array ( ) [parameters:protected] => [parameterNames:protected] => [compiled:protected] => [router:protected] => Illuminate\Routing\Router Object _RECURSION_ [container:protected] => Illuminate\Foundation\Application Object _RECURSION_ ) [test] => Illuminate\Routing\Route Object ( [uri:protected] => test [methods:protected] => Array ( [0] => GET [1] => POST [2] => HEAD ) [action:protected] => Array ( [middleware] => web [uses] => App\Http\Controllers\Test@test [controller] => App\Http\Controllers\Test@test [namespace] => App\Http\Controllers [prefix] => [where] => Array ( ) [as] => test ) ...
Can you put the full text into paste bin?
The fact that it outputs so much data is the reason the browser hangs. This is not a Laravel problem in itself.
Try using curl on the command line to execute the request, although it may take a while there as well. You may be pulling several MB's of data, really.
Use symfony's dumper component to avoid recursion.
@miscbits
it's too big for pastebin too
@JoostK
there's only one field there. it's just a simple post request.
previously(some version ago) I debug using print_r without problem. this time when I want to use it, it broke.
@GrahamCampbell
as always Laravel team will close bug without confirming it.
I think bug reporting is useless here..
@lino10 the thing you are dumping has a reference to the IoC container, so you are basically dumping every object in memory. That may amount to several megabytes, which the browser can't handle.
This is not a Laravel issue and solutions exist to circumvent this problem, as Graham suggests.
@JoostK Using dd() is not a solution. It terminates the execution. I can easily use print_r to show the output while dd() can't. Not to mention dd() has ugly output, I need to click multiple times just to see the output and obviously can't work with ajax.
If this is not Laravel issue, then what issue is it? It's working fine before.
Its an issue with PHP. when you use print_r you are dumping everything in memory which is a lot. If you need to print something do it in the view and just pass back the data.
@lino10 Neither Graham nor I mentioned dd. I would advise to insert a breakpoint (make sure you have the Xdebug extension installed) at the location you want to inspect so you may properly investigate your problem.
Try 'dump' function.
@lino10 Any luck with this issue. I'm also facing the same issue.
Hey one thing I noticed here that I didnt notice before is that this is printing out the array before printing out the web page. You shouldn't do simple prints inside of your controllers. You should die and dump the data you are looking to get. dd($var) should get you what you are looking for.
Also if you want to print the request, you should dd($request->all()) and not $request.
print_r($mycollection->toJson());
die();
Most helpful comment
@miscbits
it's too big for pastebin too
@JoostK
there's only one field there. it's just a simple post request.
previously(some version ago) I debug using print_r without problem. this time when I want to use it, it broke.
@GrahamCampbell
as always Laravel team will close bug without confirming it.
I think bug reporting is useless here..