diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index dc0b72cd6122..d5c155685e12 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -260,9 +260,6 @@ public function loadClassmap(string $class): void */ public function loadClass(string $class): void { - $class = trim($class, '\\'); - $class = str_ireplace('.php', '', $class); - $this->loadInNamespace($class); } diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index d877d66e406d..4c81537dbf09 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -20,7 +20,6 @@ use Config\Modules; use Config\Services; use InvalidArgumentException; -use PHPUnit\Framework\MockObject\MockObject; use RuntimeException; use UnnamespacedClass; @@ -34,6 +33,10 @@ final class AutoloaderTest extends CIUnitTestCase use ReflectionHelper; private Autoloader $loader; + + /** + * @phpstan-var Closure(string): (false|string) + */ private Closure $classLoader; protected function setUp(): void @@ -146,15 +149,6 @@ public function testMatchesWithPrecedingSlash(): void $this->assertSame($expected, $actual); } - public function testMatchesWithFileExtension(): void - { - /** @var Autoloader&MockObject $classLoader */ - $classLoader = $this->getMockBuilder(Autoloader::class)->onlyMethods(['loadInNamespace'])->getMock(); - $classLoader->expects($this->once())->method('loadInNamespace')->with(Home::class); - - $classLoader->loadClass('\App\Controllers\Home.php'); - } - public function testMissingFile(): void { $this->assertFalse(($this->classLoader)('\App\Missing\Classname')); diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index 5cf06105d29f..4747e953fc29 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -58,6 +58,12 @@ Property Name The property ``Factories::$basenames`` has been renamed to ``$aliases``. +Autoloader +---------- + +Previously, CodeIgniter's autoloader allowed loading class names ending with the `.php` extension. This means instantiating objects like `new Foo.php()` was possible +and would instantiate as `new Foo()`. Since `Foo.php` is an invalid class name, this behavior of the autoloader is changed. Now, instantiating such classes would fail. + .. _v440-interface-changes: Interface Changes