note 127242 added to function.spl-autoload
| From: | theking2 at king dot ma | Date: | Sat, 09 Jul 2022 10:41:07 +0000 |
| Subject: | note 127242 added to function.spl-autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218942@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.12.131 (proxied: 83.97.81.249)
----
Manual Page -- https://php.net/manual/en/function.spl-autoload.php
Edit -- https://main.php.net/note/edit/127242
Del: integrated -- https://main.php.net/note/delete/127242/integrated
Del: useless -- https://main.php.net/note/delete/127242/useless
Del: bad code -- https://main.php.net/note/delete/127242/bad+code
Del: spam -- https://main.php.net/note/delete/127242/spam
Del: non-english -- https://main.php.net/note/delete/127242/non-english
Del: in docs -- https://main.php.net/note/delete/127242/in+docs
Del: other reasons-- https://main.php.net/note/delete/127242
Reject -- https://main.php.net/note/reject/127242
Search -- https://main.php.net/manage/user-notes.php