2010-09-10 87 views
1

的錯誤可以說我有一些代碼:PHP編輯器/編譯器/不管,顯示在我的代碼

<?php 
    echo "Hello Everybody!"; 
    echo "<br/>" ; 
    $var1 = 23 ; 
    var_dump($var1) ; 

    $str = <<<HERE 

    some random text 
    more random strings 

    HERE; 

    echo $str ; 
?> 

現在運行這個對localhost作爲的index.php,給出了一個空白頁。那可能是因爲代碼中有一些錯誤。現在有什麼東西(編輯器,編譯器,什麼)會告訴我究竟在哪裏以及我的錯誤是什麼?

目前我使用那些便攜式服務器(XAMP,netserver,uniserver)來運行我的php頁面,這很好用,但它並不告訴我在我的代碼中有什麼錯誤。

謝謝

回答

2

您應該使用的工具是PHP。

確保error_reporting設置爲高的東西,如E_STRICT

In PHP 5 a new error level E_STRICT is available. As E_STRICT is not included within E_ALL you have to explicitly enable this kind of error level. Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.

+0

謝謝。我對此一無所知。將探索這個選項。 – 2010-09-10 10:14:00

+0

即使在編輯我的php.ini – 2010-09-10 10:23:17

+0

@ user161179後,我仍然得到一個空白頁 - 你重新啓動了Apache嗎? – 2010-09-10 12:17:15

0

我會讓別人回答編輯的問題。我會在代碼中回答錯誤部分:

HERE; 

HERE; 

不應該有領先的空間heredoc末端位置。從手冊:

The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

+0

謝謝,那個額外的空間是我使用的編輯器添加的。但我在這裏找到一個能告訴我這種錯誤的工具。 – 2010-09-10 10:02:26

0

許多IDE都提供了這種功能 - 在某種程度上,讓人想起了NetBeans,Dreamweaver CS5。

他們將突出顯示明顯的語法錯誤,如缺少分號/不平衡護腕。

但請記住,如果編譯器可以識別每個錯誤,那麼他們也可以修復它們。沒有想法可以幫助修復不良的編程邏輯等。

也作爲以下亮點的答案,error_reporting可以關閉,所以應該打開開發。

0

製作新的一頁,把它的index.php

error_reporting(E_ALL); 
ini_set("display_errors", 1); 
include('content.php'); 

content.php應該是頁面,你的代碼,

現在它會顯示你的錯誤! 另外我的問題,我幾天前注意到當你在一個tmp服務器上工作。

+0

將您的代碼塊縮進4個空格以獲得語法突出顯示的優點。代碼塊將源代碼中的換行符解釋爲輸出中的新行。 – 2010-09-10 10:06:13

+0

完成,'text to fill commentbox' – Jordy 2010-09-10 10:07:25

+0

此方法顯示的錯誤:解析錯誤:語法錯誤,在第27行的E:\ UniServer \ www \ content.php中出現意外的$ end。不完全準確... – 2010-09-10 10:13:39

0

僅供參考,如果你只想做一個快速語法檢查,使用-l開關與PHP的二進制文件。

php -l myscript.php