Unreasonable Errors on PHP Slim 3 Middleware
<p>I am trying to use the ValidationErrorsMiddleware.php class as a middleware, so I added the following code to my bootstrap/app.php:</p>

<pre><code>$app-&gt;add(new App\Middleware\ValidationErrorsMiddleware($container));
</code></pre>

<p>I got the following errors after the above code is added to my app.php:</p>

<pre><code>Fatal error: Uncaught exception 'RuntimeException' with message 'Unexpected data in output buffer. Maybe you have characters before an opening &lt;?php tag?' in C:\wamp64\www\authentication\vendor\slim\slim\Slim\App.php on line 552
RuntimeException: Unexpected data in output buffer. Maybe you have characters before an opening &lt;?php tag? in C:\wamp64\www\authentication\vendor\slim\slim\Slim\App.php on line 552
</code></pre>

<p>Just in case, anyone needs to look at the code of my classes and app.php, I have included them down here</p>

<hr>

<p>ValidationErrorsMiddleware.php</p>

<pre><code>&lt;?php

namespace App\Middleware;

class ValidationErrorsMiddleware extends Middleware {

  public function __invoke($request, $response, $next) {

    var_dump('middleware');
    $response = $next($request, $response);

    return $response;
  }
}
</code></pre>

<p>Middleware.php</p>

<pre><code>&lt;?php

namespace App\Middleware;

class Middleware {

protected $container;

  public function __construct($container) {

    $this-&gt;container = $container;
  }
}
</code></pre>

<p>App.php</p>

<pre><code>&lt;?php

session_start();

require __DIR__ . '/../vendor/autoload.php';

$app = new \Slim\App([
'settings' =&gt; [
    'determineRouteBeforeAppMiddleware' =&gt; false,
    'displayErrorDetails' =&gt; true,
    'db' =&gt; [
        // Eloquent configuration
        'driver' =&gt; 'mysql',
        'host' =&gt; 'localhost',
        'database' =&gt; 'phpdb',
        'username' =&gt; 'root',
        'password' =&gt; 'root',
        'charset' =&gt; 'utf8',
        'collation' =&gt; 'utf8_unicode_ci',
        'prefix' =&gt; '',
    ]
],
]);


$container = $app-&gt;getContainer();

$app-&gt;add(new App\Middleware\ValidationErrorsMiddleware($container));

require __DIR__ . '/../app/routes.php';
</code></pre>