No Code Attached Yet b/c break
avatar Fedik
Fedik
27 Oct 2025

Currently, all getInstance() methods are planned to be removed.
However not every has a proper replacement despite suggestion to use "factories".

Here a few that I found and that need a solution.

Form::getInstance() vs FormFactory::createForm().

Form::getInstance() return cached instance and also loads the data

// Load the data.
if (str_starts_with($data, '<')) {
if (!$forms[$name]->load($data, $replace, $xpath)) {
throw new \RuntimeException(\sprintf('%s() could not load form', __METHOD__));
}
} else {
if (!$forms[$name]->loadFile($data, $replace, $xpath)) {
throw new \RuntimeException(\sprintf('%s() could not load file', __METHOD__));
}
}

FormFactory::createForm() just create a new instance, and always return new.

Returning cached instance is critical when we need to manipulate the form multiple times at runtime.
Look for example subform field. Also for performance.
And removed possibility to load the data (by form name or from path) will lead to code duplication, inconsistencies and more bugs.

User::getInstance() vs UserFactory::loadById()

User::getInstance() return cached instance.
UserFactory::loadById() always return new User instance, always perfoms DB query for this user.

Returning cached instance is critical here for many use cases, especially while rendering large list of content and when extension may hook in to and also check for user. This can hurt performance.

avatar Fedik Fedik - open - 27 Oct 2025
avatar joomla-cms-bot joomla-cms-bot - change - 27 Oct 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Oct 2025
avatar Fedik Fedik - change - 27 Oct 2025
Labels Added: b/c break
avatar Fedik Fedik - labeled - 27 Oct 2025
avatar Fedik Fedik - change - 27 Oct 2025
The description was changed
avatar Fedik Fedik - edited - 27 Oct 2025
avatar sshekhar563
sshekhar563 - comment - 3 Nov 2025

Can i take this issue ?

Add a Comment

Login with GitHub to post a comment