プロジェクト

全般

プロフィール

Backport(バックポート) #3178

Yuya Watanabe11年以上前に更新

h3. 概要

三項演算子の二項目を省略した記述はPHP5.2環境で動作しない

具体的には下記コード部分がこれに該当する.

lib/util/opActivityQueryBuilder.class.php
<pre>
72 public function includeFriends($target_member_id = null)
73 {
74 $this->include['friend'] = $target_member_id ?: $this->viewerId;
75 return $this;
76 }
</pre>

apps/api/lib/helper/opJsonApiHelper.php
<pre>
134 'name' => $community->getName(),
'category' => (string)$community->getCommunityCategory() ?: null,
\136 'community_url' => $communityUrl,
</pre>

h3. 原因

三項演算子の二項目を省略した形で記述できるのは PHP 5.3 以降であるため、 PHP 5.2 環境では利用することができない.

参考URL: http://php.net/manual/ja/language.operators.comparison.php

h3. 修正内容

<pre>
diff --git a/apps/api/lib/helper/opJsonApiHelper.php b/apps/api/lib/helper/opJsonApiHelper.php
index e5fd560..c460778 100644
--- a/apps/api/lib/helper/opJsonApiHelper.php
+++ b/apps/api/lib/helper/opJsonApiHelper.php
@@ -139,7 +139,7 @@ function op_api_community($community)
return array(
'id' => $community->getId(),
'name' => $community->getName(),
- 'category' => (string)$community->getCommunityCategory() ?: null,
+ 'category' => $community->getCommunityCategory() ? $community->getCommunityCategory()->getName() : null,
'community_url' => $communityUrl,
'community_image_url' => $communityImage,
'joining' => $communityMember ? !$communityMember->getIsPre() : false,
diff --git a/lib/util/opActivityQueryBuilder.class.php b/lib/util/opActivityQueryBuilder.class.php
index 6841e90..661dec5 100644
--- a/lib/util/opActivityQueryBuilder.class.php
+++ b/lib/util/opActivityQueryBuilder.class.php
@@ -71,7 +71,7 @@ class opActivityQueryBuilder

public function includeFriends($target_member_id = null)
{
- $this->include['friend'] = $target_member_id ?: $this->viewerId;
+ $this->include['friend'] = $target_member_id ? $target_member_id : $this->viewerId;
return $this;
}

</pre>

h3. 元本文

三項演算子の省略形がPHP5.2で動作しないので、動作するように変更する。
厳密にはバグではないが、これだけの理由でPHP5.3縛りにしてしまうのはもったいない。安定版中に対応する。
すなわち、OpenPNE3.8の対象バージョンはPHP5.2以上である、ということを定義する。


{OpenPNE3.8.0}/apps/api/lib/helper
opJsonApiHelper.php
パラメータ省略は、5.3から可能
135行目
修正前
'category' => (string)$community->getCommunityCategory() ?: null,
修正後
'category' => (string)$community->getCommunityCategory() ? $community->getCommunityCategory() : null,

戻る