PHP如何使变量末定义的提示不显示!

来源:百度知道 编辑:UC知道 时间:2024/04/29 20:37:04
如 $c没有定义,会有提示。想知道如何用 改代码 和配置php.ini文件的方法取消提示。
<?php
$a=100;
$b=200;
$c=800;
function demo()
{
global $a,$b;
echo $a+$b+$c;
}
demo();
?>

文件顶端加上
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 'On');

就可以屏掉那些无关紧要的系统提示了,而程序的其他错误提示则正常显示.

你则个$c在函数内,属于局部变量。当然报错了。内存中没有这个值。

不过要去掉错误提示加error_reporting(0); 就可以了。

支持用"@",这样局部化比较安全,修改.ini的话,会影响到所有php的

文件顶端加上
error_reporting(0);

<?php
$a=100;
$b=200;
$c=800;
function demo()
{
global $a,$b;
if(!isset($c))
$c='没有定义'
echo $a+$b+$c;
}
demo();
?>

ini_set('display_errors', 'off');