Cant find class when using "Whoops!" library?

3k Views Asked by At

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
3

There are 3 best solutions below

2
Katie On BEST ANSWER

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.

0
Lajos Arpad On

Whoops namespace is either missing or it does not have a Run class. Check autoload.php and make sure it loads Whoops and the Whoops you are using has the Run class.

2
hayres On

Try using the provided example at https://code.tutsplus.com/tutorials/whoops-php-errors-for-cool-kids--net-32344 which you can see loads /vendor/autoload.php slightly differently.

The error suggest that the Whoops class is not being properly loaded.

<?php
# index.php
require __DIR__ . "/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!");
?>`

OK. Check that your paths are correct and that /vendor/ does contain whoops. the tree should be something like

-vendor

--Whoops

--autoload.php

-index.php