You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of documenting the issue of invalid namespace names, modify the Joomla extension installer to validate them. This would prevent the installation of invalid extensions and provide immediate feedback, which is a more robust solution.
Joomla does not check the extension name in the installation process. However, errors are reported later when the PHP code is executed.
Solution Walkthrough:
Before:
// Current process described by the PR's documentation
// 1. Developer defines a namespace starting with a number.
// namespace 1MyVendor\MyExtension;
// 2. Joomla's installer runs without validation.
function Installer.install(package) {
// ... no check on namespace validity ...
// Installation succeeds.
}
// 3. At runtime, PHP fails.
// PHP Fatal error: '1MyVendor' is not a valid namespace name
After:
// Suggested process with installer validation
// 1. Developer defines a namespace starting with a number.
// namespace 1MyVendor\MyExtension;
// 2. Joomla's installer validates the namespace.
function Installer.install(package) {
let namespace = getNamespaceFromManifest(package);
if (!isValidNamespace(namespace)) {
throw new InstallationError("Invalid namespace name. Namespaces cannot start with a number.");
}
// Installation is blocked, preventing runtime errors.
}
Suggestion importance[1-10]: 9
__
Why: This is an excellent high-level suggestion that addresses the root cause of the problem rather than just documenting a workaround, proposing a systemic fix that would significantly improve the framework's robustness.
High
General
Clarify namespace naming rules and link
Clarify that each segment of a PHP namespace must start with a letter or underscore, and update the reference link to the PHP manual on constants for better context.
-Attention: The first character of the namespace name is restricted to "a-zA-Z_" with some additionals. See-[PHP valid variable names](https://www.php.net/manual/en/language.variables.basics.php) -So be careful of company or extension names beginning with a number or other restricted characters. Recommendation: Use '_' as the first character instead.+Attention: Each segment of a PHP namespace must start with a letter or an underscore. See the [PHP manual on valid names](https://www.php.net/manual/en/language.constants.syntax.php) for more details.+So be careful if your company or extension name begins with a number or other restricted character. In such cases, a recommended practice is to prefix the namespace segment with an underscore (`_`).
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies an ambiguity in the documentation and provides a more precise explanation of PHP namespace naming rules, improving the quality and accuracy of the information for developers.
Low
More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
User description
defining-your-namespace.md: added info about: The first character of the namespace name is restricted to "a-zA-Z_" ....
PR Type
Documentation
Description
Added developer note about namespace character restrictions
Clarifies first character must be "a-zA-Z_" per PHP rules
Recommends using underscore prefix for names starting with numbers
Notes Joomla doesn't validate during installation, errors appear at runtime
Diagram Walkthrough
File Walkthrough
defining-your-namespace.md
Add namespace character restriction developer notedocs/general-concepts/namespaces/defining-your-namespace.md
defining-your-namespace.md
Add namespace character restriction developer noteversioned_docs/version-5.4/general-concepts/namespaces/defining-your-namespace.md
defining-your-namespace.md
Add namespace character restriction developer noteversioned_docs/version-6.0/general-concepts/namespaces/defining-your-namespace.md