未定義の変数でエラー ログを詰まらせないように、PHP 変数を定義することになっていることはわかっていますが、私のログはまだ不要な情報でいっぱいになっています。
例えば...
[28-Jan-2013 16:45:42 UTC] PHP Notice: Undefined index: site in C:\Sites\FLCBranson.org\freedownloads.php on line 34
私のPHPコードは$site
定義されていますが、それをオーバーライドするオプションが必要です...
// it's a good idea to define the variable first and then make changes as necessary (that way you don't fill up your logs with worthless errors)
$site = "flc";
// overrides the domain (useful for IP addresses)
if ($_GET["site"]) $site = $_GET["site"];
だから、私はそのタイプの問題をたくさん持っています。次に、これらの厄介なエラーがたくさんあります...
[28-Jan-2013 16:45:42 UTC] PHP Notice: Undefined offset: 3 in C:\Sites\FLCBranson.org\listseries.php on line 264
[28-Jan-2013 16:45:42 UTC] PHP Notice: Undefined offset: 4 in C:\Sites\FLCBranson.org\listseries.php on line 265
[28-Jan-2013 16:45:42 UTC] PHP Notice: Undefined offset: 5 in C:\Sites\FLCBranson.org\listseries.php on line 266
さまざまなコンテンツが取り込まれた配列があります。スロットに何かが入っていたら、それをどうにかしたい...
// explode() takes a string of text ($item->title in this case) and creates an array comprised of parts of the text separated by the separator (- in this case)
$title = explode(" - ", $sermontitle);
// sets the sermon title variable
$sermontitle = $title[0];
if ($title[1]) $sermontitle = $sermontitle . " - " . $title[1];
if ($title[2]) $sermontitle = $sermontitle . "<br>" . $title[2];
if ($title[3]) $sermontitle = $sermontitle . " - " . $title[3];
if ($title[4]) $sermontitle = $sermontitle . " - " . $title[4];
if ($title[5]) $sermontitle = $sermontitle . " - " . $title[5];
それで、私は間違って何をしていますか?変数を定義します。次に、特定の条件が満たされた場合にのみ変数を変更します。それが適切な方法だと思いました。
編集...
別の奇妙な例を見つけました...
[28-Jan-2013 20:07:05 UTC] PHP Notice: Undefined variable: broadcast in C:\Sites\FLCBranson.org\flconlineservices.php on line 242
それだけでif (file_exists($golive) || ($broadcast == "live")
は十分ではないようです。する必要がありますif (file_exists($golive) || (isset($broadcast) && $broadcast == "live"))
か? これは、単純な比較を実行するための大量のコードのように思えます。
編集 2...
だから、なぜisset()
必要なのか理解し始めていますが、ここに私が得られないことがあります。データベースから情報を取得するコードがいくつかありますif ($row["Sarasota"])
が、エラーログにはそのための単一のものが表示されません。に必要な場合、なぜisset()
そこに必要ないのでしょうif ($title[5])
か? 私が見ることができる唯一の違いは、引用されていない数字の 5 とは対照的に、引用された単語 "Sarasota" です。