Nucleus CMSの新リリースを準備するためのリポジトリ。現在はNucleus CMS 4.0にマージするためのコードをコミットしている。
Revisão | 6575e866f3fd1938601432841d80f82e9d259265 (tree) |
---|---|
Hora | 2012-09-17 14:48:48 |
Autor | sakamocchi <o-takashi@saka...> |
Commiter | sakamocchi |
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()の関数呼び出しを修正したほか、より誤解の少ないコードに変更した。
@@ -228,8 +228,10 @@ class BlogImport { | ||
228 | 228 | } |
229 | 229 | |
230 | 230 | // - 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); | |
233 | 235 | } |
234 | 236 | |
235 | 237 | if ($this->bDebug) { |
@@ -405,7 +405,7 @@ class Actions extends BaseActions | ||
405 | 405 | $params = func_get_args(); |
406 | 406 | array_shift($params); |
407 | 407 | |
408 | - return call_user_func_array(array(&$plugin, 'doIf'), $params); | |
408 | + return call_user_func_array(array($plugin, 'doIf'), $params); | |
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -1865,7 +1865,7 @@ class Actions extends BaseActions | ||
1865 | 1865 | // add skin type on front |
1866 | 1866 | array_unshift($params, $this->skintype); |
1867 | 1867 | |
1868 | - call_user_func_array(array(&$plugin,'doSkinVar'), $params); | |
1868 | + call_user_func_array(array($plugin,'doSkinVar'), $params); | |
1869 | 1869 | return; |
1870 | 1870 | } |
1871 | 1871 |
@@ -960,7 +960,8 @@ class AdminActions extends BaseActions | ||
960 | 960 | case 'delete': |
961 | 961 | if ( $this->skintype != 'batchteam' ) |
962 | 962 | { |
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); | |
964 | 965 | } |
965 | 966 | else |
966 | 967 | { |
@@ -968,7 +969,8 @@ class AdminActions extends BaseActions | ||
968 | 969 | } |
969 | 970 | break; |
970 | 971 | 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); | |
972 | 974 | break; |
973 | 975 | case 'setadmin': |
974 | 976 | // always succeeds |
@@ -4361,7 +4363,7 @@ class AdminActions extends BaseActions | ||
4361 | 4363 | |
4362 | 4364 | if ( method_exists($this, $met) ) |
4363 | 4365 | { |
4364 | - $value = call_user_func(array(&$this, $met), $arg); | |
4366 | + $value = call_user_func(array($this, $met), $arg); | |
4365 | 4367 | } |
4366 | 4368 | } |
4367 | 4369 |
@@ -4852,7 +4854,7 @@ class AdminActions extends BaseActions | ||
4852 | 4854 | $params = func_get_args(); |
4853 | 4855 | array_shift($params); |
4854 | 4856 | |
4855 | - return call_user_func_array(array(&$plugin, 'doIf'), $params); | |
4857 | + return call_user_func_array(array($plugin, 'doIf'), $params); | |
4856 | 4858 | } |
4857 | 4859 | |
4858 | 4860 | /** |
@@ -107,9 +107,10 @@ class BodyActions extends BaseActions | ||
107 | 107 | array_shift($params); |
108 | 108 | |
109 | 109 | // 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); | |
111 | 112 | |
112 | - call_user_func_array(array(&$plugin, 'doItemVar'), $params); | |
113 | + call_user_func_array(array($plugin, 'doItemVar'), $params); | |
113 | 114 | return; |
114 | 115 | } |
115 | 116 |
@@ -126,7 +127,7 @@ class BodyActions extends BaseActions | ||
126 | 127 | // image/popup calls have arguments separated by | |
127 | 128 | $args = func_get_args(); |
128 | 129 | $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); | |
130 | 131 | } |
131 | 132 | |
132 | 133 | /** |
@@ -174,7 +175,7 @@ class BodyActions extends BaseActions | ||
174 | 175 | // image/popup calls have arguments separated by | |
175 | 176 | $args = func_get_args(); |
176 | 177 | $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); | |
178 | 179 | } |
179 | 180 | |
180 | 181 | /** |
@@ -215,7 +216,7 @@ class BodyActions extends BaseActions | ||
215 | 216 | // image/popup calls have arguments separated by | |
216 | 217 | $args = func_get_args(); |
217 | 218 | $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); | |
219 | 220 | } |
220 | 221 | |
221 | 222 | /** |
@@ -558,6 +559,6 @@ class BodyActions extends BaseActions | ||
558 | 559 | $params = func_get_args(); |
559 | 560 | array_shift($params); |
560 | 561 | |
561 | - return call_user_func_array(array(&$plugin, 'doIf'), $params); | |
562 | + return call_user_func_array(array($plugin, 'doIf'), $params); | |
562 | 563 | } |
563 | 564 | } |
@@ -434,7 +434,7 @@ class BaseActions | ||
434 | 434 | { |
435 | 435 | $this->addIfExecute(); |
436 | 436 | $args = func_get_args(); |
437 | - $condition = call_user_func_array(array(&$this,'checkCondition'), $args); | |
437 | + $condition = call_user_func_array(array($this,'checkCondition'), $args); | |
438 | 438 | $this->addIfCondition($condition); |
439 | 439 | return; |
440 | 440 | } |
@@ -505,7 +505,7 @@ class BaseActions | ||
505 | 505 | { |
506 | 506 | ob_end_clean(); |
507 | 507 | $args = func_get_args(); |
508 | - $condition = call_user_func_array(array(&$this,'checkCondition'), $args); | |
508 | + $condition = call_user_func_array(array($this,'checkCondition'), $args); | |
509 | 509 | $this->addIfCondition($condition); |
510 | 510 | } |
511 | 511 | return; |
@@ -523,7 +523,7 @@ class BaseActions | ||
523 | 523 | $this->addIfExecute(); |
524 | 524 | |
525 | 525 | $args = func_get_args(); |
526 | - $condition = call_user_func_array(array(&$this,'checkCondition'), $args); | |
526 | + $condition = call_user_func_array(array($this,'checkCondition'), $args); | |
527 | 527 | $this->addIfCondition(!$condition); |
528 | 528 | return; |
529 | 529 | } |
@@ -559,7 +559,7 @@ class BaseActions | ||
559 | 559 | { |
560 | 560 | ob_end_clean(); |
561 | 561 | $args = func_get_args(); |
562 | - $condition = call_user_func_array(array(&$this,'checkCondition'), $args); | |
562 | + $condition = call_user_func_array(array($this,'checkCondition'), $args); | |
563 | 563 | $this->addIfCondition(!$condition); |
564 | 564 | } |
565 | 565 | return; |
@@ -537,10 +537,12 @@ class CommentActions extends BaseActions | ||
537 | 537 | array_shift($params); |
538 | 538 | |
539 | 539 | // 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); | |
542 | 544 | |
543 | - call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params); | |
545 | + call_user_func_array(array($plugin,'doTemplateCommentsVar'), $params); | |
544 | 546 | return; |
545 | 547 | } |
546 | 548 |
@@ -1005,6 +1007,6 @@ class CommentActions extends BaseActions | ||
1005 | 1007 | $params = func_get_args(); |
1006 | 1008 | array_shift($params); |
1007 | 1009 | |
1008 | - return call_user_func_array(array(&$plugin, 'doIf'), $params); | |
1010 | + return call_user_func_array(array($plugin, 'doIf'), $params); | |
1009 | 1011 | } |
1010 | 1012 | } |
@@ -753,9 +753,10 @@ class ItemActions extends BaseActions | ||
753 | 753 | array_shift($params); |
754 | 754 | |
755 | 755 | // 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); | |
757 | 758 | |
758 | - call_user_func_array(array(&$plugin,'doTemplateVar'), $params); | |
759 | + call_user_func_array(array($plugin,'doTemplateVar'), $params); | |
759 | 760 | return; |
760 | 761 | } |
761 | 762 |
@@ -1121,6 +1122,6 @@ class ItemActions extends BaseActions | ||
1121 | 1122 | $params = func_get_args(); |
1122 | 1123 | array_shift($params); |
1123 | 1124 | |
1124 | - return (boolean) call_user_func_array(array(&$plugin, 'doIf'), $params); | |
1125 | + return (boolean) call_user_func_array(array($plugin, 'doIf'), $params); | |
1125 | 1126 | } |
1126 | 1127 | } |
@@ -571,7 +571,7 @@ class Manager | ||
571 | 571 | && !empty($this->plugins[$listener]) |
572 | 572 | && method_exists($this->plugins[$listener], 'event_' . $eventName) ) |
573 | 573 | { |
574 | - call_user_func(array(&$this->plugins[$listener], 'event_' . $eventName), $data); | |
574 | + call_user_func(array($this->plugins[$listener], 'event_' . $eventName), $data); | |
575 | 575 | } |
576 | 576 | } |
577 | 577 | } |
@@ -737,7 +737,7 @@ class MediaObject | ||
737 | 737 | return FALSE; |
738 | 738 | } |
739 | 739 | |
740 | - $original = call_user_func_array($function, array(&$fullpath)); | |
740 | + $original = call_user_func_array($function, $fullpath); | |
741 | 741 | if ( !$original ) |
742 | 742 | { |
743 | 743 | return FALSE; |
@@ -135,7 +135,7 @@ class Parser | ||
135 | 135 | |
136 | 136 | if ( in_array($actionlc, $this->actions) || $this->norestrictions ) |
137 | 137 | { |
138 | - call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params); | |
138 | + call_user_func_array(array($this->handler, "parse_{$actionlc}"), $params); | |
139 | 139 | } |
140 | 140 | else |
141 | 141 | { |
@@ -99,7 +99,7 @@ abstract class NucleusPlugin | ||
99 | 99 | $args = func_get_args(); |
100 | 100 | array_shift($args); |
101 | 101 | array_unshift($args, 'template'); |
102 | - call_user_func_array(array(&$this,'doSkinVar'),$args); | |
102 | + call_user_func_array(array($this, 'doSkinVar'), $args); | |
103 | 103 | return; |
104 | 104 | } |
105 | 105 |
@@ -109,7 +109,7 @@ abstract class NucleusPlugin | ||
109 | 109 | array_shift($args); |
110 | 110 | array_shift($args); |
111 | 111 | array_unshift($args, 'template'); |
112 | - call_user_func_array(array(&$this,'doSkinVar'),$args); | |
112 | + call_user_func_array(array($this, 'doSkinVar'), $args); | |
113 | 113 | return; |
114 | 114 | } |
115 | 115 |
@@ -1092,7 +1092,8 @@ | ||
1092 | 1092 | // 3rd API convention for method-handling functions: EPI-style |
1093 | 1093 | if ($this->functions_parameters_type == 'epivals') |
1094 | 1094 | { |
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); | |
1096 | 1097 | // mimic EPI behaviour: if we get an array that looks like an error, make it |
1097 | 1098 | // an eror response |
1098 | 1099 | if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r)) |