关于“输出缓冲区中的意外数据”与PHP标记或结束PHP标记之前的字符无关的细微错误

I have this simple code structure:

api.php:

<?php
    require_once 'api/Main.class.php';
    new Main();

api/Main.class.php:

<?php
    require_once __DIR__ . '../../vendor/autoload.php';
    require_once 'Router/Router.class.php';

    class Main
    {

        function __construct()
        {
            $router = new Router();
            $router->getRoute();
        }

    }

Router/Router.class.php:

<?php
    use \Psr\Http\Message\ServerRequestInterface as Request;
    use \Psr\Http\Message\ResponseInterface as Response;

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

    class Router
    {

        function getRoute()
        {
            $app = new \Slim\App;

            $app->get(
                '/',
                function (Request $request, Response $response, array $args) {
                    $response->getBody()->write('Home');

                    return $response;
                }
            );

            $app->run();
        }

    }

This produces the following error when I go to api.php: <b>Fatal error</b>: Uncaught RuntimeException: Unexpected data in output buffer. Maybe you have characters before an opening &lt;?php tag? in /Path/to/project/root/vendor/slim/slim/Slim/App.php:625

This error doesn't give me much information. I've been trying to get Slim to work in an OOP codebase, but this error keeps popping up every time I try this.

I've also tried returning $app, so I can run t elsewhere, which also produces the same error. What is going wrong in this code?