Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trimming logic of Autoloader::loadClass() #7763

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 4 additions & 10 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Config\Modules;
use Config\Services;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use RuntimeException;
use UnnamespacedClass;

Expand All @@ -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
Expand Down Expand Up @@ -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'));
Expand Down
6 changes: 6 additions & 0 deletions user_guide_src/source/changelogs/v4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down