古いコンポーネントのコードをリファクタリングしていて、この警告に遭遇しました:
Strict standards: Non-static method JUserHelper::getProfile() should not be called statically, assuming $this from incompatible context
$ userProfile = JUserHelper :: getProfile($ userId);
警告の技術的な性質は理解していますが、getProfile
はstatic
として宣言されていないため、JUserHelper
は抽象的であるため、インスタンス化できません。
奇妙なことに、クラス内の他のすべてのメソッドはstatic
として定義されています。 3.xと同様に、2.5ではバグのように見えますが、署名は異なります。
では、プロファイルを取得する適切な方法は何ですか?
それはバグです。
これは、J3開発中に13-Jul-2012 c7c372のプラットフォームアップデートの一部として修正されました。
プラットフォームの変更は、2012年7月3日の99b6ac PR1341で、最初にCMSトラッカーアイテム28633を調達した後に行われました。
バグ33717を提起し、J2.5に対するパッチを提供した@valentinの功績によるものです。
はい、おそらくバージョン2.5のバグです。 JUserHelperのgetProfile()関数はjoomla 2.5ディストリビューションのどこでも使用されていないため、バグが無人になる可能性があると思います。今宣言されているとおりに使用するには、JUserHelper-クラスをサブクラス化する必要がありますが、これは実際には意味がありません。
これはバグで、静的がありません http://prntscr.com/3hl3t1
静的インプレースプリント
$userProfile = JUserHelper::getProfile(42);
print_r( $userProfile );
戻り値
とりあえず、関数をコピーして、このように使用できます
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 );