Uncaught Error: Call to undefined method App\App::run() in Slim-4 php and php-di

934 views Asked by At

While working with Slim and PHP-DI, got a warning saying

Uncaught Error: Call to undefined method App\App::run()

The code is as follows:

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

$app = new \DI\Bridge\Slim\Bridge;
$app->run();
1

There are 1 answers

0
Gursewak Singh On

In latest version of PHP-DI, there are some changes

DI\Bridge\Slim\App has changed to DI\Bridge\Slim\Bridge. So if you are using use DI\Bridge\Slim\App as DiBridge; may not work. Instead try use DI\Bridge\Slim\Bridge as DiBridge;

There is no $app->run() method defined in PHP-DI Bridge class, hence its undefined. Instead use $app->create() method.

Note

In order to use create() method on $app, make sure you have slim/psr7 installed, otherwise you may see a bloody red warning. If you dont have slim/psr7 installed use the following command to get it installed

composer require slim/psr7

So after making sure slim/psr7 is there, code must look as follows

require __DIR__ . "/../vendor/autoload.php";
$app = new \DI\Bridge\Slim\Bridge;
$app->create();