2009-12-15 52 views
0

我有一個腳本,在我們的開發服務器上正常工作,但死在客戶端服務器上。如何捕獲死亡的PHP腳本錯誤(Perl有eval)?

error_reporting(E_ALL); 
if (function_exists('simplexml_load_file')) echo "function exists"; 
if (file_exists('test.xml')) 
{ 
echo("<hr>just about to read local xml file :".__LINE__); 
$xml = simplexml_load_file('test.xml'); // dies here 

在Perl中,你可以用eval捕獲這樣的錯誤,在PHP中是否有任何等價的東西?

回答

0

取決於函數失敗的方式。

simplexml_load_file()的情況下,該錯誤信息是well documented

On errors, it will return FALSE.

Produces an E_WARNING error message for each error found in the XML data.

Tip

Use libxml_use_internal_errors() to suppress all XML errors, and libxml_get_errors() to iterate over them afterwards.

而且,您可以隨時set your own error handler或使用(麻煩) error suppression operator

+0

彼得 它從來沒有從simplexml_load_file返回,試過你的建議無濟於事 – zzapper 2009-12-15 17:19:33

+0

是他們的服務器PHP 5? – 2009-12-15 17:29:58

+0

是的,他們的系統管理員在工作,但也有問題 – zzapper 2009-12-15 17:34:33

0

系統管理員: - 我簡要地打開詳細的錯誤報告和它回來與此:

致命錯誤:在

無法複製類的SimpleXMLElement由於 「zend.ze1_compatibility_mode」的對象http://archives.devshed.com/forums/php-108/simplexml-problem-982459.html

這種配置可以在每個站點的覆蓋與 .htaccess文件指令 http://www.activecollab.com/forums/topic/616/

this solved the problem. But why couldn't I turn on this level of error reporting from within my script?