Skip to content

Commit 9151860

Browse files
authored
Merge pull request #7763 from paulbalandan/autoloader-loadclass
Remove trimming logic of `Autoloader::loadClass()`
2 parents b496f46 + b93b35b commit 9151860

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

system/Autoloader/Autoloader.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ public function loadClassmap(string $class): void
260260
*/
261261
public function loadClass(string $class): void
262262
{
263-
$class = trim($class, '\\');
264-
$class = str_ireplace('.php', '', $class);
265-
266263
$this->loadInNamespace($class);
267264
}
268265

tests/system/Autoloader/AutoloaderTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Config\Modules;
2121
use Config\Services;
2222
use InvalidArgumentException;
23-
use PHPUnit\Framework\MockObject\MockObject;
2423
use RuntimeException;
2524
use UnnamespacedClass;
2625

@@ -34,6 +33,10 @@ final class AutoloaderTest extends CIUnitTestCase
3433
use ReflectionHelper;
3534

3635
private Autoloader $loader;
36+
37+
/**
38+
* @phpstan-var Closure(string): (false|string)
39+
*/
3740
private Closure $classLoader;
3841

3942
protected function setUp(): void
@@ -146,15 +149,6 @@ public function testMatchesWithPrecedingSlash(): void
146149
$this->assertSame($expected, $actual);
147150
}
148151

149-
public function testMatchesWithFileExtension(): void
150-
{
151-
/** @var Autoloader&MockObject $classLoader */
152-
$classLoader = $this->getMockBuilder(Autoloader::class)->onlyMethods(['loadInNamespace'])->getMock();
153-
$classLoader->expects($this->once())->method('loadInNamespace')->with(Home::class);
154-
155-
$classLoader->loadClass('\App\Controllers\Home.php');
156-
}
157-
158152
public function testMissingFile(): void
159153
{
160154
$this->assertFalse(($this->classLoader)('\App\Missing\Classname'));

user_guide_src/source/changelogs/v4.4.0.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Property Name
5858

5959
The property ``Factories::$basenames`` has been renamed to ``$aliases``.
6060

61+
Autoloader
62+
----------
63+
64+
Previously, CodeIgniter's autoloader allowed loading class names ending with the `.php` extension. This means instantiating objects like `new Foo.php()` was possible
65+
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.
66+
6167
.. _v440-interface-changes:
6268

6369
Interface Changes

0 commit comments

Comments
 (0)