开发者

php editor/compiler/whatever that shows errors in my code

Lets say I have some code:

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

  $str = <<<HERE

  some random text
  more random strings

  HERE;

  echo $str ;
?>

Now running this as index.php on localhost , gives a blank page. Thats probab开发者_运维问答ly because there is some error in the code. Now is there something(editor,compiler,whatever) that will tell me exactly where and what my error is ?

Currently I use one of those portable servers (XAMP , netserver,uniserver) to run my php pages, which works good , but it doesn't tell me what errors are there in my code.

Thanks


The tool you should use for this is PHP.

Make sure error_reporting is set to something high, such as 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.


I'll let others to answer the question of the editor. I'll answer the error part in the code:

  HERE;

to

HERE;

There should be no leading space where the heredoc ends. From the manual:

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.


Check your php.ini to see if error_reporting is turned off.


Many IDEs offer this functionality - NetBeans being one that comes to mind, Dreamweaver CS5 to a certain extent.

They will highlight blatant syntax errors like missing semicolons/unbalanced bracers.

But bear in mind if a compiler could identify every error then they could fix them too. no idea will help fix poor programming logic etc.

also as an answer below highlights, error_reporting can be turned off so should be turned on for development.


Make new page, call it index.php

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

content.php should be the page where your code is,

Now it will show your error! Also i problem i noticed couple of days ago when you're working on a tmp-server.


FYI, if you just want to do a quick syntax check, use the -l switch with the php binary.

php -l myscript.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜