Complete the code to define the base namespace prefix for PSR-4 autoloading.
$prefix = "[1]\\";
The base namespace prefix is usually the project or application name, like App.
Complete the code to map the namespace prefix to the directory path in PSR-4.
$baseDir = __DIR__ . '/[1]/';
The src directory is commonly used to store PHP source files for PSR-4 mapping.
Fix the error in the autoloader function to correctly replace namespace prefix with directory path.
if (strncmp($class, $prefix, [1]) !== 0) { return; }
We compare the start of the class name with the length of the namespace prefix.
Fill both blanks to correctly build the file path from the class name.
$relativeClass = substr($class, [1]); $file = $baseDir . str_replace([2], '/', $relativeClass) . '.php';
We remove the prefix length from the class name and replace backslashes with slashes for file paths.
Fill all three blanks to complete the PSR-4 autoloader registration code.
spl_autoload_register(function ($class) { $prefix = '[1]\\'; $baseDir = __DIR__ . '/[2]/'; if (strncmp($class, $prefix, [3]) !== 0) { return; } });
This code registers an autoloader that maps the App\ namespace to the src directory and checks the prefix length correctly.