我们在运用PHP常见错误是:
No page rendered by the Web browser when much more is expected
A pop-up dialog stating that the "Document Contains No Data"
A partial page when more is expected
出现这些PHP常见错误情况的大多数原因并不在于脚本的逻辑,而是 HTML 中存在的 bug 或者脚本生成的 HTML 的 bug 。例如缺少类似 , , 之类的关闭 Tag,页面就不能刷新。解决这个问题的办法就是,查看 HTML 的源代码。
对于复杂的,不能查到原因的页面,可以通过 W3C 的页面校验程序 http://validator.w3.org/来分析。
如果没有定义变量,或者变量定义错误也会让程序变得古怪。例如下面的死循环:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span> </span></span></li> <li class=""> <span>for($</span><span class="attribute">counter</span><span>=</span><span class="attribute-value">0</span><span>; $counter</span><span class="tag"><span class="tag-name">10</span><span>; $Counter++) </span></span> </li> <li class="alt"><span>myFunction(); </span></li> <li class=""> <span></span><span class="tag">?></span><span> </span> </li> </ol>
变量 $Counter 在增加,而 $counter 永远小于 10。这类PHP常见错误一般都能通过设置较高的错误报告级别来找到:
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li> <li class=""><span>error_reporting(E_ALL); </span></li> <li class="alt"><span> </span></li> <li class=""> <span>for($</span><span class="attribute"><font color="#ff0000">counter</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>; $counter</span><strong><font color="#006699"><span class="tag"><span class="tag-name">10</span></span></font></strong><span>; $Counter++) </span> </li> <li class="alt"><span>myFunction(); </span></li> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>