Refactor applyAliasFor method formatting #46300
Open
+9
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


// applyAliasFor($class) : Check that the alias does not already exist before creating it. in order to avoid an error such as: Cannot declare class joomla\cms\filesystem\folder, because the name is already in use
Pull Request for Issue # .
Summary of Changes
This PR updates the applyAliasFor($class) method in libraries/loader.php to check whether an alias already exists before creating it with class_alias().
This prevents errors like: Warning: Cannot declare class joomla\cms\filesystem\folder, because the name is already in use
Testing Instructions
Go to the Joomla administrator dashboard.
Install or enable an extension that triggers a duplicate alias for a core class (e.g., joomla\cms\filesystem\folder).
Reload the dashboard page.
✅ Expected behavior after applying this patch:
No PHP warning is thrown.
The dashboard loads correctly.
Actual result BEFORE applying this Pull Request
Warning: Cannot declare class joomla\cms\filesystem\folder, because the name is already in use
The page may break or the back-office interface may not render correctly.
Expected result AFTER applying this Pull Request
No warning about duplicate class declaration.
Normal page rendering.
applyAliasFor skips already existing aliases gracefully.
Link to documentations
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed