稍后我会解释这一点:全局变量
class num
{
function num1()
{
global $error;
$error="This is an error message";
return false;
}
function num2()
{
global $error;
return $error;
}
}
$num=new num();
$check=$num->num1();
if($check===false) $error.="There is another error message";
die($error);//This is an error messageThere is another error message
在功能num1
$error
影响$error
类外。有关如何防止这种情况的任何建议?
您错过了分号,在返回虚假陈述结束 – Sandesh
谢谢,但这不是我想要得到的答案:D但是,谢谢。 – 131
我想它是因为你使用全局。停止它,它不会影响对象外部的$错误。 –