0

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
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Stuart Little
  • 33
  • 1
  • 4

3 Answers3

1

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.

Katie
  • 2,594
  • 3
  • 23
  • 31
  • It didn't have your composer code it just had "{ }" although when I updated my composer.json to yours and ran composer update in the directory the composer.json was located it threw an error. "./composer.json" does not contain valid JSON Parse error on line 1: "require": { "flip/whoops --------^ Expected one of: 'EOF', '}', ',', ']' – Stuart Little Nov 27 '16 at 12:44
  • OK, I'll update with the whole file...this should work. This is what you get when you run composer require filp/whoops 1.* (at least the require part). – Katie Nov 27 '16 at 12:45
0

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.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
0

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

hayres
  • 120
  • 1
  • 11
  • This outputs the same error, didn't change anything. – Stuart Little Nov 27 '16 at 12:36
  • OK. Check that your paths are correct and that /vendor/ does contain whoops. I have put the comment in the answer as i cannot format it here. Basically it looks like to me it is not loading Whoops correctly. – hayres Nov 27 '16 at 12:39