php通知php 5.4+的未定义错误

BBK*_*ing -4 php

可能重复:
PHP:"注意:未定义的变量"和"通知:未定义的索引"

PHP 5.4.4在localhost中升级/安装(xampp 1.8.0).现在我notice error在我的页面中看到很多.什么问题?怎么解决这个问题?

错误之处:

Notice: Undefined index: language in C:\xampp\htdocs\tube\include\config.php on line 93

Notice: Undefined variable: max_avatar_width in C:\xampp\htdocs\tube\include\lang\english.php on line 495

Notice: Undefined variable: max_avatar_height in C:\xampp\htdocs\tube\include\lang\english.php on line 496

Notice: Undefined index: USERID in C:\xampp\htdocs\tube\index.php on line 26
Run Code Online (Sandbox Code Playgroud)

配置PHP页面:

if ($_REQUEST['language'] != '') // <---- Line 93 
{
    if ($_REQUEST['language'] == 'english')
    {

        $_SESSION['language'] = 'english';
    }
    elseif ($_REQUEST['language'] == 'spanish')
    {

        $_SESSION['language'] = 'spanish';
    }
}

if ($_SESSION['language'] == "")
{

    $_SESSION['language'] = "english";
}

if ($_SESSION['language'] == "english")
{
include("lang/english.php");
}
elseif ($_SESSION['language'] == "spanish")
{
include("lang/spanish.php");
}
else
{
include("lang/english.php");
}
Run Code Online (Sandbox Code Playgroud)

英语Lang Page(第495和496行):

$lang['491'] =  "The image width is too big. Max width is $max_avatar_width pixels."; 
$lang['492'] =  "The image height is too big. Max height is $max_avatar_height pixels.";
Run Code Online (Sandbox Code Playgroud)

索引PHP页面:

if($_SESSION['USERID'] == "") // <-- Line 26
{
    $showfamfilter = "AND mature='0'";
}
elseif($_SESSION['FAMILYFILTER'] == "0")
{
    $showfamfilter = "";
}
else
{
    $showfamfilter = "AND mature='0'";
}
Run Code Online (Sandbox Code Playgroud)

Eve*_*ert 6

您可以将error_reportingphp.ini中的设置更改为不包含E_NOTICE.php.ini文件中应该有一些例子.

但是,这是不明智的..你应该做的是修复你的代码.例如,而不是:

if ($_REQUEST['language'] != '')
Run Code Online (Sandbox Code Playgroud)

你应该写:

if (isset($_REQUEST['language']))
Run Code Online (Sandbox Code Playgroud)

修复所有E_NOTICE错误将使您的代码更加健壮.

  • @PoulsQ:如果你看一下他的源代码,那么isset实际上会给出正确的行为.这些行的行为并不相同,但完整的脚本是. (2认同)