• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-next: Commit

Nucleus CMSの新リリースを準備するためのリポジトリ。現在はNucleus CMS 4.0にマージするためのコードをコミットしている。


Commit MetaInfo

Revisão6575e866f3fd1938601432841d80f82e9d259265 (tree)
Hora2012-09-17 14:48:48
Autorsakamocchi <o-takashi@saka...>
Commitersakamocchi

Mensagem de Log

FIX: リファレンスにまつわるコードを修正

1. リファレンス渡しは関数定義でのみ有効であり、関数呼び出しでは致命的なエラーとなる
参照: http://php.net/manual/en/language.references.pass.php
引用: 「注意: 関数コールの際には、リファレンス記号がないことに注意してください。
関数定義にのみリファレンス記号があります。リファレンスで正しく引数を 渡すには、関数定義のみで十分です。以前のバージョンの PHP では
foo(&$a); のような形式で & を利用すると "Call-time pass-by-reference"
という警告が発生していましたが、 PHP 5.3.0 以降では警告は発生しません。 また、PHP 5.4.0 以降では
call-time pass-by-reference 機能自体が削除されたので、 これを使おうとすると fatal エラーが発生します。」

2.callableタイプヒントとして配列宣言をしてオブジェクトのインスタンスとメソッドを渡す場合、配列の一つ目のインスタンスは自動でリファレンス参照として扱われる。
参照: http://php.net/manual/en/language.types.callable.php
引用: 「注意: PHP 4 では、実際のオブジェクトを指すコールバックを作成するには、
コピーではなく参照を使わなければなりませんでした。 詳細は 参照についての説明 を参照ください。」

上記を踏まえ、参照を伴うcall_user_func()/call_user_func_array()、array_merge()の関数呼び出しを修正したほか、より誤解の少ないコードに変更した。

Mudança Sumário

Diff

--- a/nucleus/convert/functions.inc.php
+++ b/nucleus/convert/functions.inc.php
@@ -228,8 +228,10 @@ class BlogImport {
228228 }
229229
230230 // - call callback
231- if ($this->strCallback && function_exists($this->strCallback)) {
232- call_user_func_array($this->strCallback, array(&$aData));
231+ if ( $this->strCallback && function_exists($this->strCallback) )
232+ {
233+ $params = array(&$aData);
234+ call_user_func_array($this->strCallback, $params);
233235 }
234236
235237 if ($this->bDebug) {
--- a/nucleus/libs/ACTIONS.php
+++ b/nucleus/libs/ACTIONS.php
@@ -405,7 +405,7 @@ class Actions extends BaseActions
405405 $params = func_get_args();
406406 array_shift($params);
407407
408- return call_user_func_array(array(&$plugin, 'doIf'), $params);
408+ return call_user_func_array(array($plugin, 'doIf'), $params);
409409 }
410410
411411 /**
@@ -1865,7 +1865,7 @@ class Actions extends BaseActions
18651865 // add skin type on front
18661866 array_unshift($params, $this->skintype);
18671867
1868- call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1868+ call_user_func_array(array($plugin,'doSkinVar'), $params);
18691869 return;
18701870 }
18711871
--- a/nucleus/libs/AdminActions.php
+++ b/nucleus/libs/AdminActions.php
@@ -960,7 +960,8 @@ class AdminActions extends BaseActions
960960 case 'delete':
961961 if ( $this->skintype != 'batchteam' )
962962 {
963- $error = call_user_func_array(array('Admin', $deleteaction), array($selectedid));
963+ $params = array($selectedid);
964+ $error = call_user_func_array(array('Admin', $deleteaction), $params);
964965 }
965966 else
966967 {
@@ -968,7 +969,8 @@ class AdminActions extends BaseActions
968969 }
969970 break;
970971 case 'move':
971- $error = call_user_func_array(array('Admin', $moveaction), array($selectedid, $destid));
972+ $params = array($selectedid, $destid);
973+ $error = call_user_func_array(array('Admin', $moveaction), $params);
972974 break;
973975 case 'setadmin':
974976 // always succeeds
@@ -4361,7 +4363,7 @@ class AdminActions extends BaseActions
43614363
43624364 if ( method_exists($this, $met) )
43634365 {
4364- $value = call_user_func(array(&$this, $met), $arg);
4366+ $value = call_user_func(array($this, $met), $arg);
43654367 }
43664368 }
43674369
@@ -4852,7 +4854,7 @@ class AdminActions extends BaseActions
48524854 $params = func_get_args();
48534855 array_shift($params);
48544856
4855- return call_user_func_array(array(&$plugin, 'doIf'), $params);
4857+ return call_user_func_array(array($plugin, 'doIf'), $params);
48564858 }
48574859
48584860 /**
--- a/nucleus/libs/BODYACTIONS.php
+++ b/nucleus/libs/BODYACTIONS.php
@@ -107,9 +107,10 @@ class BodyActions extends BaseActions
107107 array_shift($params);
108108
109109 // add item reference (array_unshift didn't work)
110- $params = array_merge(array(&$this->currentItem), $params);
110+ $target = array(&$this->currentItem);
111+ $params = array_merge($target, $params);
111112
112- call_user_func_array(array(&$plugin, 'doItemVar'), $params);
113+ call_user_func_array(array($plugin, 'doItemVar'), $params);
113114 return;
114115 }
115116
@@ -126,7 +127,7 @@ class BodyActions extends BaseActions
126127 // image/popup calls have arguments separated by |
127128 $args = func_get_args();
128129 $args = preg_split('#\|#', implode($args, ', '));
129- echo call_user_func_array(array(&$this, 'createImageCode'), $args);
130+ echo call_user_func_array(array($this, 'createImageCode'), $args);
130131 }
131132
132133 /**
@@ -174,7 +175,7 @@ class BodyActions extends BaseActions
174175 // image/popup calls have arguments separated by |
175176 $args = func_get_args();
176177 $args = preg_split('#\|#', implode($args, ', '));
177- echo call_user_func_array(array(&$this, 'createMediaCode'), $args);
178+ echo call_user_func_array(array($this, 'createMediaCode'), $args);
178179 }
179180
180181 /**
@@ -215,7 +216,7 @@ class BodyActions extends BaseActions
215216 // image/popup calls have arguments separated by |
216217 $args = func_get_args();
217218 $args = preg_split('#\|#', implode($args, ', '));
218- echo call_user_func_array(array(&$this, 'createPopupCode'), $args);
219+ echo call_user_func_array(array($this, 'createPopupCode'), $args);
219220 }
220221
221222 /**
@@ -558,6 +559,6 @@ class BodyActions extends BaseActions
558559 $params = func_get_args();
559560 array_shift($params);
560561
561- return call_user_func_array(array(&$plugin, 'doIf'), $params);
562+ return call_user_func_array(array($plugin, 'doIf'), $params);
562563 }
563564 }
--- a/nucleus/libs/BaseActions.php
+++ b/nucleus/libs/BaseActions.php
@@ -434,7 +434,7 @@ class BaseActions
434434 {
435435 $this->addIfExecute();
436436 $args = func_get_args();
437- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
437+ $condition = call_user_func_array(array($this,'checkCondition'), $args);
438438 $this->addIfCondition($condition);
439439 return;
440440 }
@@ -505,7 +505,7 @@ class BaseActions
505505 {
506506 ob_end_clean();
507507 $args = func_get_args();
508- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
508+ $condition = call_user_func_array(array($this,'checkCondition'), $args);
509509 $this->addIfCondition($condition);
510510 }
511511 return;
@@ -523,7 +523,7 @@ class BaseActions
523523 $this->addIfExecute();
524524
525525 $args = func_get_args();
526- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
526+ $condition = call_user_func_array(array($this,'checkCondition'), $args);
527527 $this->addIfCondition(!$condition);
528528 return;
529529 }
@@ -559,7 +559,7 @@ class BaseActions
559559 {
560560 ob_end_clean();
561561 $args = func_get_args();
562- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
562+ $condition = call_user_func_array(array($this,'checkCondition'), $args);
563563 $this->addIfCondition(!$condition);
564564 }
565565 return;
--- a/nucleus/libs/COMMENTACTIONS.php
+++ b/nucleus/libs/COMMENTACTIONS.php
@@ -537,10 +537,12 @@ class CommentActions extends BaseActions
537537 array_shift($params);
538538
539539 // pass info on current item and current comment as well
540- $params = array_merge(array(&$this->currentComment), $params);
541- $params = array_merge(array(&$this->commentsObj->itemActions->currentItem), $params);
540+ $target = array(&$this->currentComment);
541+ $params = array_merge($target, $params);
542+ $target = array(&$this->commentsObj->itemActions->currentItem);
543+ $params = array_merge($target, $params);
542544
543- call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);
545+ call_user_func_array(array($plugin,'doTemplateCommentsVar'), $params);
544546 return;
545547 }
546548
@@ -1005,6 +1007,6 @@ class CommentActions extends BaseActions
10051007 $params = func_get_args();
10061008 array_shift($params);
10071009
1008- return call_user_func_array(array(&$plugin, 'doIf'), $params);
1010+ return call_user_func_array(array($plugin, 'doIf'), $params);
10091011 }
10101012 }
--- a/nucleus/libs/ITEMACTIONS.php
+++ b/nucleus/libs/ITEMACTIONS.php
@@ -753,9 +753,10 @@ class ItemActions extends BaseActions
753753 array_shift($params);
754754
755755 // add item reference (array_unshift didn't work)
756- $params = array_merge(array(&$this->currentItem),$params);
756+ $target = array(&$this->currentItem);
757+ $params = array_merge($target,$params);
757758
758- call_user_func_array(array(&$plugin,'doTemplateVar'), $params);
759+ call_user_func_array(array($plugin,'doTemplateVar'), $params);
759760 return;
760761 }
761762
@@ -1121,6 +1122,6 @@ class ItemActions extends BaseActions
11211122 $params = func_get_args();
11221123 array_shift($params);
11231124
1124- return (boolean) call_user_func_array(array(&$plugin, 'doIf'), $params);
1125+ return (boolean) call_user_func_array(array($plugin, 'doIf'), $params);
11251126 }
11261127 }
--- a/nucleus/libs/MANAGER.php
+++ b/nucleus/libs/MANAGER.php
@@ -571,7 +571,7 @@ class Manager
571571 && !empty($this->plugins[$listener])
572572 && method_exists($this->plugins[$listener], 'event_' . $eventName) )
573573 {
574- call_user_func(array(&$this->plugins[$listener], 'event_' . $eventName), $data);
574+ call_user_func(array($this->plugins[$listener], 'event_' . $eventName), $data);
575575 }
576576 }
577577 }
--- a/nucleus/libs/MEDIA.php
+++ b/nucleus/libs/MEDIA.php
@@ -737,7 +737,7 @@ class MediaObject
737737 return FALSE;
738738 }
739739
740- $original = call_user_func_array($function, array(&$fullpath));
740+ $original = call_user_func_array($function, $fullpath);
741741 if ( !$original )
742742 {
743743 return FALSE;
--- a/nucleus/libs/PARSER.php
+++ b/nucleus/libs/PARSER.php
@@ -135,7 +135,7 @@ class Parser
135135
136136 if ( in_array($actionlc, $this->actions) || $this->norestrictions )
137137 {
138- call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params);
138+ call_user_func_array(array($this->handler, "parse_{$actionlc}"), $params);
139139 }
140140 else
141141 {
--- a/nucleus/libs/PLUGIN.php
+++ b/nucleus/libs/PLUGIN.php
@@ -99,7 +99,7 @@ abstract class NucleusPlugin
9999 $args = func_get_args();
100100 array_shift($args);
101101 array_unshift($args, 'template');
102- call_user_func_array(array(&$this,'doSkinVar'),$args);
102+ call_user_func_array(array($this, 'doSkinVar'), $args);
103103 return;
104104 }
105105
@@ -109,7 +109,7 @@ abstract class NucleusPlugin
109109 array_shift($args);
110110 array_shift($args);
111111 array_unshift($args, 'template');
112- call_user_func_array(array(&$this,'doSkinVar'),$args);
112+ call_user_func_array(array($this, 'doSkinVar'), $args);
113113 return;
114114 }
115115
--- a/nucleus/libs/xmlrpcs.inc.php
+++ b/nucleus/libs/xmlrpcs.inc.php
@@ -1092,7 +1092,8 @@
10921092 // 3rd API convention for method-handling functions: EPI-style
10931093 if ($this->functions_parameters_type == 'epivals')
10941094 {
1095- $r = call_user_func_array($func, array($methName, $params, $this->user_data));
1095+ $params = array($methName, $params, $this->user_data);
1096+ $r = call_user_func_array($func, $params);
10961097 // mimic EPI behaviour: if we get an array that looks like an error, make it
10971098 // an eror response
10981099 if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r))
Show on old repository browser