user1492901
user1492901

Reputation: 39

Cannot find existing key in array

I'm working with composer and I have the following classmap:

return array(
'Wit\\Cache\\CacheAdapterInterface' => $baseDir . '/src/Wit/Cache/CacheAdapterInterface.php',
'Wit\\Cache\\CacheManager' => $baseDir . '/src/Wit/Cache/CacheManager.php',
'Wit\\Cache\\FileAdapter' => $baseDir . '/src/Wit/Cache/FileAdapter.php',
'Wit\\Cache\\RedisAdapter' => $baseDir . '/src/Wit/Cache/RedisAdapter.php',
'Wit\\Request\\Request' => $baseDir . '/src/Wit/Request/Request.php',
    'Wit\\Zenpoint\\ZenpointUser' => $baseDir . '/src/Wit/Zenpoint/ZenpointUser.php',
    'Wit\\Zenpoint\\ZenpointConfig' => $baseDir . '/src/Wit/Zenpoint/ZenpointConfig.php',
    'Wit\\Zenpoint\\ZenpointCarrello' => $baseDir . '/src/Wit/Zenpoint/ZenpointCarrello.php',
    'Wit\\Zenpoint\\ZenpointAcquisitions' => $baseDir . '/src/Wit/Zenpoint/ZenpointAcquisitions.php',
    'Wit\\Zenpoint\\ZenpointAcquisition' => $baseDir . '/src/Wit/Zenpoint/ZenpointAcquisition.php',
    'Wit\\Cart\\ZipCodeChecker' => $baseDir . '/src/Wit/Cart/ZipCodeChecker.php',
    'Wit\\Cart\\ZipCodeLoader' => $baseDir . '/src/Wit/Cart/ZipCodeLoader.php',
    'Wit\\Complimentary\\OmaggioOrdine' => $baseDir . '/src/Wit/Complimentary/OmaggioOrdine.php',
    'Wit\\Complimentary\\PacchettoOmaggio' => $baseDir . '/src/Wit/Complimentary/PacchettoOmaggio.php',
    'Wit\\Complimentary\\ProdottiAScelta' => $baseDir . '/src/Wit/Complimentary/ProdottiAScelta.php',
    'Wit\\Complimentary\\OmaggioLoader' => $baseDir . '/src/Wit/Complimentary/OmaggioLoader.php',
    'Wit\\Complimentary\\PacchettoLoader' => $baseDir . '/src/Wit/Complimentary/PacchettoLoader.php',
    'Wit\\Complimentary\\ProdottiASceltaLoader' => $baseDir . '/src/Wit/Complimentary/ProdottiASceltaLoader.php',
    'Wit\\Complimentary\\ProdottiLoader' => $baseDir . '/src/Wit/Complimentary/ProdottiLoader.php',
);

I then have the following in a file: use WIT\Complimentary\OmaggioLoader;

The problem is that PHP says it cannot find the class:

Fatal error: Class 'WIT\ComplimentaryProducts\OmaggioLoader' not found.

The first thing I thought was that the path was wrong, but it doesn't seem so. So I tried to see what was happening in the Composer ClassLoader.php file and dumped the following:

var_dump($class); //string(31) "WIT\Complimentary\OmaggioLoader"
var_dump(array_keys($this->classMap)); //[15]=> string(31) "Wit\Complimentary\OmaggioLoader"
var_dump(array_key_exists($class, $this->classMap)); //bool(false)
var_dump($this->classMap[$class]); //NULL
var_dump($this->classMap['Wit\\Complimentary\\OmaggioLoader']);//string(69) "/path/to/Wit/Complimentary/OmaggioLoader.php"

So, why PHP cannot find the array element if the key is correct? Why if I insert it manually, will PHP finds it?

Upvotes: 0

Views: 87

Answers (1)

Max Zuber
Max Zuber

Reputation: 1229

Class names in PHP are case insensitive, array keys are not. They have different beginning.

Upvotes: 2

Related Questions