PHPverse 2025

Voting

: min(five, nine)?
(Example: nine)

The Note You're Voting On

theking2 at king dot ma
2 years ago
Both namespaces and class names are case insensitive. This can cause problems with autoloading in OS/filesystems that _are_

Consider this code:
<?php declare(strict_types=1);
set_include_path(get_include_path() . PATH_SEPARATOR . 'class/');
spl_autoload_extensions('.class.php');
spl_autoload_register();

$foobar = new \foo\bar();
?>

and a class file /class/foo/bar.class.php:
<?php declare(strict_types=1);
namespace
Foo;

class
Bar {
public function
__construct() {
echo
'Map constructed';
}
}
?>

this will work fine regardless of a case sensitive or not case sensitive OS/FS.

A file called ./class/Foo/Bar.class.php will only be found on a not case sensitive situation as the default class loader will mb_strtolower() the class name to find the class filename.

Btw. this content of a class file will be equivalent to the one above:
<?php declare(strict_types=1);
namespace
foo;

class
bar {
public function
__construct() {
echo
'Map constructed';
}
}
?>

The class /foo/bar and /Foo/Bar are one and the same thing.

<< Back to user notes page

To Top