Search code examples
phpwhoops

Cant find class when using "Whoops!" library?


Recently I have been trying the Whoops! library and trying to get it to work, however, unfortunately this is the closest I have gotten to get it working.

I installed it via the composer using this tutorial https://code.tutsplus.com/tutorials/whoops-php-errors-for-cool-kids--net-32344

PHP:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

# index.php
require(getcwd() . "/vendor/autoload.php");

$whoops = new Whoops\Run();
$whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());

// Set Whoops as the default error and exception handler used by PHP:
$whoops->register();

throw new RuntimeException("Oopsie!");
?>

Error:

Fatal error: Uncaught Error: Class 'Whoops\Run' not found in C:\Users\Administrator\Desktop\CMS\app\library\whoops\index.php:9 Stack trace: #0 {main} thrown in C:\Users\Administrator\Desktop\CMS\app\library\whoops\index.php on line 9

Solution

  • I just ran your code and it ran fine for me (it actually did nothing, but the class loaded just fine). Check your composer.json and ensure it has:

    {
        "name": "root/stack-overflow",
        "minimum-stability": "stable",
        "require": {
            "filp/whoops": "1.*"
        }
    }
    

    Run composer update just to be sure. And lastly ensure that your index.php is in the directory that has vendor as a subdirectory.