Missing Import Errors in PHP
PHP's Class 'X' not found and Call to undefined function errors mean the autoloader can't find your class or the function isn't imported.
Namespace Use Statements
// Error: Class 'Request' not found
// Fix: add use statement
use Illuminate\Http\Request;
class UserController extends Controller
{
public function store(Request $request)
{
// ...
}
}Composer Autoload
After adding a new class, regenerate the autoloader:
composer dump-autoloadPSR-4 Mapping
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}This maps App\Models\User to src/Models/User.php. The namespace must match the directory structure.
Missing Composer Package
composer require guzzlehttp/guzzle
composer require league/flysystemPHP Built-in Functions
In namespaced code, built-in functions might need a leading backslash:
namespace App\Utils;
// If you have a local function with the same name,
// use \ to access the global one
$time = \time();
$encoded = \json_encode($data);Common Laravel Imports
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;Bugsly captures Class not found errors in PHP with the full namespace and autoload configuration, making it straightforward to diagnose PSR-4 mapping issues.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Fix Missing Import in Vue
Resolve component and module import errors in Vue.js applications, covering auto-imports, Composition API, and Vite/Webpack resolution.
Read moreHow to Decode JWT Tokens Safely (Without Leaking Secrets)
Learn how JWTs work, how to decode them safely for debugging, and why you should never paste tokens into random online tools.
Read moreHow to Fix DNS Resolution Error in PHP
Learn how to fix the DNS Resolution Error in PHP. Step-by-step guide with code examples.
Read moreHow to Fix DatabaseError in Python
Learn how to fix the DatabaseError in Python. Step-by-step guide with code examples.
Read more