5

I was refactoring some code in an older component and I came across this warning:

Strict standards: Non-static method JUserHelper::getProfile() should not be called statically, assuming $this from incompatible context 

$userProfile = JUserHelper::getProfile($userId);

While I do understand the technical nature of the warning, as getProfile is not declared static, JUserHelper is abstract, so it cannot be instantiated.

Curiously all other methods in the class are define as static. Looks like a bug in 2.5 to me as in 3.x the signature is different.

So what is the proper way to get the profile?

4
  • I try this with Joomla 3.3.0 and have no problems so far with strict standarts... May 9, 2014 at 7:35
  • Just in 2.5 is it defined like this. May 9, 2014 at 7:36
  • Is there a specific reason why you need to use JUserHelper::getProfile(), or would you be able to get by with JFactory::getUser() instead?
    – Lodder
    May 9, 2014 at 9:13
  • I need to read values from the user profile. May 9, 2014 at 9:16

3 Answers 3

7

It's a bug.

This was fixed during J3 development as part of a platform update on 13-Jul-2012 c7c372.

The plaform change was made on 3-Jul-2012 99b6ac PR1341 after initially raising CMS tracker item 28633.

Credit to @valentin for raising bug 33717 and supplying a patch against J2.5.

0
4

Yes, it is most probably a bug in the 2.5 - version. The getProfile()-function in JUserHelper is not used anywhere in the joomla 2.5-distribution, so the bug could go unattended, I guess. To use it as it is declared now you would have to subclass the JUserHelper - class, which really makes no sense.

3

It is a bug , missing static http://prntscr.com/3hl3t1

with static in place print

$userProfile = JUserHelper::getProfile(42);
print_r( $userProfile );

returns

http://prntscr.com/3hl3x7

for time being you can copy the function over and use it like this

function MygetProfile($userId = 0)
{
    if ($userId == 0)
    {
        $user   = JFactory::getUser();
        $userId = $user->id;
    }

    // Get the dispatcher and load the user's plugins.
    $dispatcher = JDispatcher::getInstance();
    JPluginHelper::importPlugin('user');

    $data = new JObject;
    $data->id = $userId;

    // Trigger the data preparation event.
    $dispatcher->trigger('onContentPrepareData', array('com_users.profile', &$data));

    return $data;
}
$userProfile = MygetProfile(42);
print_r( $userProfile );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.