diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index bc18bd31b980..6f241e847be3 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -273,12 +273,15 @@ public function findQualifiedNameFromPath(string $path) } if (mb_strpos($path, $namespace['path']) === 0) { - $className = '\\' . $namespace['prefix'] . '\\' . - ltrim(str_replace( + $className = $namespace['prefix'] . '\\' . + ltrim( + str_replace( '/', '\\', mb_substr($path, mb_strlen($namespace['path'])) - ), '\\'); + ), + '\\' + ); // Remove the file extension (.php) $className = mb_substr($className, 0, -4); diff --git a/tests/system/Autoloader/FileLocatorTest.php b/tests/system/Autoloader/FileLocatorTest.php index 1cf32cfa5ad1..0d084280f520 100644 --- a/tests/system/Autoloader/FileLocatorTest.php +++ b/tests/system/Autoloader/FileLocatorTest.php @@ -278,7 +278,7 @@ public function testListFilesWithoutPath(): void public function testFindQNameFromPathSimple(): void { $ClassName = $this->locator->findQualifiedNameFromPath(SYSTEMPATH . 'HTTP/Header.php'); - $expected = '\\' . Header::class; + $expected = Header::class; $this->assertSame($expected, $ClassName); } diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index b64f9b3997a7..89910fa84f3d 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -33,6 +33,8 @@ Others - **Logger:** The :php:func:`log_message()` function and the logger methods in ``CodeIgniter\Log\Logger`` now do not return ``bool`` values. The return types have been fixed to ``void`` to follow the PSR-3 interface. +- **Autoloader:** The prefix ``\`` in the fully qualified classname returned by + ``FileLocator::findQualifiedNameFromPath()`` has been removed. Interface Changes ================= diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst index 240203f4b888..0a868831503c 100644 --- a/user_guide_src/source/installation/upgrade_450.rst +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -72,6 +72,14 @@ reversed. Previous: route1 → route2 → filter1 → filter2 Now: route2 → route1 → filter2 → filter1 +FileLocator::findQualifiedNameFromPath() +======================================== + +In previous versions, ``FileLocator::findQualifiedNameFromPath()`` returns Fully +Qualified Classnames with a leading ``\``. Now the leading ``\`` has been removed. + +If you have code that expects a leading ``\``, fix it. + Removed Deprecated Items ========================