PHP Class Not Found But It's Included
You are staring at a Fatal error: Class 'User' not found while your IDE confidently suggests properties like $username and methods like createUser. Your file paths look correct, the variable $ENGINE is defined, and you have double-checked the casing. This specific dissonance between what PHP reports and what your editor tells you is a classic source of frustration because it feels like the language itself is lying.
The root cause here is almost certainly a case sensitivity mismatch in the file extension or the namespace expectation, combined with how PHP resolves global class names. Let's break down exactly why require_once($ENGINE."/classUser.php") fails to expose new User().
In Windows environments, such as the XAMPP stack shown in your error log, the filesystem is case-insensitive. However, the PHP runtime and its autoloading mechanisms are not. When you write new User(), PHP looks for a file named exactly User.php relative to the include path or current directory. It does not automatically append .php if you haven't defined an autoloader, nor does it strip extensions from the class name unless explicitly told to do so via spl_autoload_register.
Your code uses require_once($ENGINE."/classUser.php"). If that file physically exists at that path, PHP executes it. However, inside classUser.php, you have defined a class named User. This is valid syntax, but notice the filename: classUser.php. While PHP permits defining a class in a file with a different name, strict adherence to PSR naming conventions and many modern frameworks suggest the filename should match the class name (e.g., User.php).
The critical issue arises if there is a subtle discrepancy between the filename on disk and what PHP expects, or if the $ENGINE variable resolves to a location where the casing of the file extension differs. If your physical file is named ClassUser.php (capital C) but your code references it as classUser.php, Windows will load the file without complaining because the OS normalizes the path. However, if you were running this on Linux or macOS, PHP would throw a "failed to open stream" error immediately. Since you are getting a "Class not found" error instead, the file did load successfully, meaning the syntax inside is valid.
Waitâif the file loaded and defined class User { ... }, why does new User() fail? The answer lies in the execution context. If signup.php includes classUser.php, and that file defines class User, then new User() should work perfectly fine, provided no other namespaces are interfering.
There is a very common pitfall in this specific scenario: Namespace pollution or incorrect autoloading expectations. If your project relies on Composer or a framework where classes are expected to live in the global namespace but are actually being loaded via an autoloader that expects User.php, you might be hitting a conflict. However, looking strictly at the vanilla PHP code provided, the most likely culprit is actually simpler: The file extension mismatch inside the include path resolution.
If $ENGINE resolves to a directory where the file is actually named ClassUser.php (with a capital C), but your require_once calls it as classUser.php, Windows loads it. But if there is any environment variable or configuration forcing strict case sensitivity, or if you are using a specific PHP version that behaves strictly, the class might not be registered in the global scope before execution proceeds.
Another possibility, often missed by developers relying on IDEs, is that the IDE (NetBeans) is indexing a different version of the file than the one currently executing. The error message points to line 12 in signup.php. If you have multiple instances of User defined or if a previous require failed silently due to path issues, the global registry remains empty.
To resolve this definitively without guessing:
- Check the exact filename on disk. Ensure it is strictly
classUser.php. If it isClassUser.php, change yourrequire_onceline to match the filesystem casing exactly. - Verify the class definition. Ensure there are no typos in
class User {. The keywordclassand the nameUsermust be exact. - Check for previous includes. If another script included a different
Userclass that failed, ensure you aren't relying on a cached state.
If you are maintaining a legacy codebase like this, consider refactoring to use PSR-4 autoloading. It removes the brittle dependency on filenames matching include paths and handles case sensitivity consistently across environments. Tools like LaravelCompany often advocate for this modernization path when dealing with inconsistent legacy PHP projects, ensuring that your class resolution logic is decoupled from filesystem quirks.
Ultimately, the error isn't a mystery; it's a signal that the global namespace does not contain a User class at the moment of instantiation, likely due to a case-sensitivity edge case or a failed load in a stricter environment than you suspect. Fix the filename casing to match the require_once string exactly, and the error will vanish.
