Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shivamyadav's avatar

Fatal error: Uncaught Error: Class "Response" not found

code

<?php

class Response{
    const NOT_FOUND = 404;
    const FORBIDDEN = 403;
}
?>

calling it

if ($note['user_id'] != $currentUserId) {
   return abort(Response::FORBIDDEN);  
}
0 likes
8 replies
vincent15000's avatar

That's PHP basics.

When you want to use a class, you need to declare it.

use Response;
...
if ($note['user_id'] != $currentUserId) {
   return abort(Response::FORBIDDEN);  
}

To avoid any conflict, I would probably use another class name because response is already used in the framework.

RAN001's avatar

Thanks it worked. I just added require 'response.php' to code

1 like
amitsolanki24_'s avatar

@shivamyadav Try this code

  namespace your_file_path;

  class Response{
    const NOT_FOUND = 404;
    const FORBIDDEN = 403;
 }

namespace like be

     namespace App\services\Response;

And where you want to use this class use namespace path like

    use App\services\Response;
1 like
vincent15000's avatar

@amitsolanki24_ It's not a good idea to use exactly the same name Response than the one already included in Laravel. Furthermore is it a response or a service ? Are you sure it's good idea to put this code inside the Services folder ?

1 like

Please or to participate in this conversation.