* PHP 5.1.1 で大量の Notice が出る [#g07d4a71] - ページ: [[BugTrack2]] - 投稿者: [[teanan]] - 優先順位: 重要 - 状態: 着手 - 状態: 却下 - カテゴリー: 本体バグ - 投稿日: 2005-12-29 (木) 10:54:42 - バージョン: ** メッセージ [#ef024fca] PHP Version 5.1.1 の環境で、error_reporting(E_ALL) にして PukiWiki-1.4.6 を動作させると Notice が大量に出ます。 Notice: Only variable references should be returned by reference in ***/lib/convert_html.php on line 144 ** 参考 [#wb5afc78] - http://ns1.php.gr.jp/pipermail/php-users/2005-July/026821.html - http://ns1.php.gr.jp/pipermail/php-users/2005-July/026821.html 直接の原因は参照返しの関数でnewしたオブジェクトをそのままreturnしている ことにあります。とりあえずバッファ変数に入れてあげることで対応するしかな いです。 ** 関連 [#j48cfc35] - [[BugTrack/632]] PHP5で動作しない - [[BugTrack2/106]] PHP5.0.5でFatal error - [[BugTrack2/82]] php-5.1.0b2で正常動作しない。 - [[BugTrack2/185]] PHP 4.4.0 および PHP 5.1.0 以降では、式の結果や new 演算子の結果をそのまま返そうとした場合に E_NOTICE エラーとなる。 -------- *コメント [#u90fe433] - Noticeが出ないように、対策してみました。 -- [[teanan]] &new{2005-12-29 (木) 11:40:35}; -- [[cvs:lib/convert_html.php]] (1.17) [[diff to 1.16>cvs:lib/convert_html.php?r1=1.16&r2=1.17]] -- [[teanan]] &new{2005-12-29 (木) 11:38:24}; - lib/convert_html.phpを1.17にしたらPHP4.4.0で動かなくなりました。エラーメッセージは Fatal error: Call to a member function on a non-object in /var/www/trunk/lib/convert_html.php on line 51 です。PHP5.1.1では問題なく動きました((paraeditパッチをあてたときの問題は依然としてありますが。)) -- [[okkez]] &new{2005-12-29 (木) 15:50:44}; -- PHP4.4.1でも同じエラーが出ました。 -- [[okkez]] &new{2005-12-29 (木) 17:06:55}; - ご迷惑をおかけして申し訳ないです。至急調査します。 -- [[teanan]] &new{2005-12-29 (木) 22:38:44}; - PHP 4.3.8にてエラーです。 -- [[hirokasa]] &new{2005-12-29 (木) 23:02:14}; - とりあえず、cvsを前のリビジョンに戻しました。 -- [[teanan]] &new{2005-12-29 (木) 23:23:33}; -- お疲れ様です。今後という事で構わないのですが、「元に戻す」作業は基本的に(機械的にやるならばcvs up -j 1.17. -j 1.16 のような形で)過去の差分を元に戻したものを新しいリビジョンとしてコミット(back out)していただけないでしょうか。リビジョン管理上そうすべきであり、何が問題でどう直すべきか検討するためにも履歴があると助かります。-o は最終手段とお考え下さい :) リビジョンが存在しなくなるので、cvsクライアントを混乱させることにもなります。-- [[henoheno]] &new{2005-12-30 (金) 15:41:46}; -- 了解いたしました。ご迷惑をおかけして申し訳ありません。 -- [[teanan]] &new{2006-01-01 (日) 14:02:09}; -- 該当のリビジョン 1.17 をcheckoutした[[冒険者]]向け: cvs up しても該当のファイルが 1.16 に戻っていない場合、一旦そのファイルをどかすなり削除なりしてから cvs up をやり直して下さい。 -- [[henoheno]] &new{2006-01-04 (水) 16:53:39}; - いえいえ。現状の対応案はどんなものだったのでしょうか :) -- [[henoheno]] &new{2006-01-04 (水) 16:46:24}; -- このような形で対応しました。Factory_hoge 全て同様の対応です。 -- [[teanan]] &new{2006-01-05 (木) 03:38:31}; function & Factory_DList(& $root, $text) { $out = explode('|', ltrim($text), 2); if (count($out) < 2) { - return Factory_Inline($text); + $_ret_object = Factory_Inline($text); } else { - return new DList($out); + $_ret_object = new DList($out); } + return $_ret_object; } - ありがとうございます。そういえばコミットメールでこのパターンの差分が来ていました (^^; -- [[henoheno]] &new{2006-01-05 (木) 23:41:19}; - [[BugTrack2/185]] -- &new{2006-06-23 (金) 23:07:05}; - PHP 5.2.1において、convert_html.php,v 1.18がNotice出しています。 -- &new{2007-05-20 (日) 07:27:56}; Notice: Only variable references should be returned by reference in lib/convert_html.php on line 102 Notice: Only variable references should be returned by reference in lib/convert_html.php on line 154 上記と同じ問題のようです。 lib/convert_html.php(100): return new Paragraph(' ' . substr($text, 1)); lib/convert_html.php(102): return new Inline($text); lib/convert_html.php(112): return new DList($out); lib/convert_html.php(122): return new Table($out); lib/convert_html.php(132): return new YTable(csv_explode(',', substr($text, 1))); lib/convert_html.php(145): return new Div($matches); lib/convert_html.php(154): return new Div($matches); // Seems legacy block plugin lib/convert_html.php(157): return new Div($matches); // Seems multiline-enabled block plugin lib/convert_html.php(162): return new Paragraph($text); lib/convert_html.php以外は大丈夫そうです。 - [[cvs:lib/convert_html.php]] (1.20) を次のように修正する場合はどうでしょうか。 // Returns inline-related object function & Factory_Inline($text) { // Check the first letter of the line if (substr($text, 0, 1) == '~') { - return new Paragraph(' ' . substr($text, 1)); + $_ret_object = & new Paragraph(' ' . substr($text, 1)); } else { - return new Inline($text); + $_ret_object = & new Inline($text); } + return $_ret_object; } function & Factory_DList(& $root, $text) { $out = explode('|', ltrim($text), 2); if (count($out) < 2) { - return Factory_Inline($text); + $_ret_object = & Factory_Inline($text); } else { - return new DList($out); + $_ret_object = & new DList($out); } + return $_ret_object; } // '|'-separated table function & Factory_Table(& $root, $text) { if (! preg_match('/^\|(.+)\|([hHfFcC]?)$/', $text, $out)) { - return Factory_Inline($text); + $_ret_object = & Factory_Inline($text); } else { - return new Table($out); + $_ret_object = & new Table($out); } + return $_ret_object; } // Comma-separated table function & Factory_YTable(& $root, $text) { if ($text == ',') { - return Factory_Inline($text); + $_ret_object = & Factory_Inline($text); } else { - return new YTable(csv_explode(',', substr($text, 1))); + $_ret_object = & new YTable(csv_explode(',', substr($text, 1))); } + return $_ret_object; } function & Factory_Div(& $root, $text) { $matches = array(); // Seems block plugin? if (PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) { // Usual code if (preg_match('/^\#([^\(]+)(?:\((.*)\))?/', $text, $matches) && exist_plugin_convert($matches[1])) { - return new Div($matches); + $_ret_object = & new Div($matches); + return $_ret_object; } } else { // Hack code if(preg_match('/^#([^\(\{]+)(?:\(([^\r]*)\))?(\{*)/', $text, $matches) && exist_plugin_convert($matches[1])) { $len = strlen($matches[3]); $body = array(); if ($len == 0) { - return new Div($matches); // Seems legacy block plugin + $_ret_object = & new Div($matches); // Seems legacy block plugin + return $_ret_object; } else if (preg_match('/\{{' . $len . '}\s*\r(.*)\r\}{' . $len . '}/', $text, $body)) { $matches[2] .= "\r" . $body[1] . "\r"; - return new Div($matches); // Seems multiline-enabled block plugin + $_ret_object = & new Div($matches); // Seems multiline-enabled block plugin + return $_ret_object; } } } - return new Paragraph($text); + $_ret_object = & new Paragraph($text); + return $_ret_object; } teanan さんの対応案との違いは、参照渡しでバッファ変数に代入したかどうか、だけなんですけど。&br;こちらでは、PHP 5.2.3 とPHP 4.3.11 でエラーがでないのを確認しました。&br;他のバージョンでも問題がなければ、今度こそ解決なんですけど。 -- &new{2007-10-08 (月) 19:19:26}; -- Factory_Inline関数にて代入する変数名(もしくはreturnする変数名)が間違ってる気がする -- [[Makichan]] &new{2007-10-09 (火) 20:56:50}; // Returns inline-related object function & Factory_Inline($text) { // Check the first letter of the line if (substr($text, 0, 1) == '~') { - return new Paragraph(' ' . substr($text, 1)); + $_ret_object = & new Paragraph(' ' . substr($text, 1)); } else { - return new Inline($text); + $_ret_object = & new Inline($text); } + return $_ret_object; } // やりとりを簡潔にしましたよ -- henoheno // ありがとうございます。リストの階層がこっちのほうが適切かなと思ったので修正しました -- Makichan // 構造的にはその方がいいみたいですね。この場で何が起こったかなんて解る人間はリアルに眺めてた人しかいないだろうけど、Wikiならではのコラボレーションのできる人にはもっと増えてもらいたいな :) ((お、一応バックアップに残ってるかー))-- henoheno -- コピペするさいに、そこだけコードがごっちゃになってました(汗)。もともと$obj でテストしていたのをこっちに載せる際に、teanan さんの対応案にあわせて$_ret_object に修正したのですが、漏れがあったようです。指摘ありがとうございます。直しました。 -- &new{2007-10-10 (水) 00:27:37}; #comment