Zend:php 页面中未定义的变量
我有一个 error.php 文件,可以将其大大简化为:
<?
if (!isset($error))
$error = "Unspecified Error";
echo "Error: $error";
?>
仅导航到 error.php 不是“正常用法”。相反,我会做类似的事情:
$dbh = mysql_connect($host, $user, $pass);
if (!$dbh)
{
$error = "Can't connect to MySQL: " . mysql_error();
include('error.php');
exit();
}
也就是说,如果用户确实导航到error.php,那么他们只会按预期得到“错误:未指定的错误”。
我的所有代码都正常工作,并且错误页面显示并完全按预期工作,但是 Zend 抱怨 $error 在行上未定义:if (!isset($error))
。
我意识到我的设计模式很糟糕,但在这种情况下我只是将一些快速而肮脏的东西放在一起。
I have an error.php file which can be grossly simplified to:
<?
if (!isset($error))
$error = "Unspecified Error";
echo "Error: $error";
?>
It is not "normal usage" to just navigate to error.php. Rather, I would do something like:
$dbh = mysql_connect($host, $user, $pass);
if (!$dbh)
{
$error = "Can't connect to MySQL: " . mysql_error();
include('error.php');
exit();
}
That said, if the user does navigate to error.php then they will just get "Error: Unspecified Error" as expected.
All my code is working, and the error page shows up and works exactly as expected, however Zend is complaining that $error is undefined on the line: if (!isset($error))
.
I realise my design pattern is awful, but I'm just throwing together something quick-and-dirty in this case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更好的主意,创建一个函数:
它的好处是既可以消除 Zend 问题,又可以让您拥有更好的设计。然后:
Better idea, create a function instead:
It has the benefit of both removing the Zend issue, and you have a MUCH better design. Then:
试试这个:
if (!isset(@$error))
。Try this:
if (!isset(@$error))
.