Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById(0);
Joomla uses this line for creating an empty User object around line 287 in ..\libraries\src\User\User.php
// If the $id is zero, just return an empty User.
// Note: don't cache this user because it'll have a new ID on save!
if ($id === 0) {
return Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById($id);
}
You would need to add the appropriate statements for Factory
and UserFactoryInterface
in your code to get the object from the container by adding 'Use' statements, or use the following:
$user = \Joomla\CMS\Factory::getContainer()->get('user.factory')->loadUserById(0);
clone()
a function defined within Joomla? I mean, PHP has object cloning which has been mentioned at What is the purpose of cloning JUri in the CMSApplication route method?. However, I'm not able to find any documentation on the technique that you are implementing. Can you share any information that you have on that? Oh wait, are you just using unneeded parentheses and smashing the magic method into the parentheses?