PHPWarningSyntax ErrorJune 20, 2026

Syntax Error

Cannot redeclare class App\Controllers\UserController in /var/www/html/app/Controllers/UserController.php on line 10

What This Error Means

This error occurs when PHP encounters a duplicate definition of a class, interface, function, or constant within the same scope.

Why It Happens

This error typically happens when a file is included multiple times in the application, causing the same class or function to be defined multiple times. This can be due to autoloading, include statements, or third-party libraries.

How to Fix It

  1. 1To fix this error, ensure that the class or function is not defined multiple times within the same scope. This can be achieved by using autoloading correctly, checking for duplicate include statements, or refactoring the code to use a different scope for the class or function.

Example Code Solution

❌ Before (problematic code)
PHP
// User.php
namespace App;\n
class User {
    public function __construct() {
        // code here
    }
}\n
// UserController.php
namespace App\Controllers;\n
class UserController extends User {
    // code here
}\n
✅ After (fixed code)
PHP
// User.php
namespace App;\n
class User {
    public function __construct() {
        // code here
    }
}\n
class UserController extends App\User {
    // code here
}

Fix for Cannot redeclare class App\Controllers\UserController in /var/www/html/app/Controllers/UserController.php on line 10

Related PHP Errors

Related PHP Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error