tags:

views:

48

answers:

6

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 probably 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

A: 

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.

codaddict
thanks, that extra space was added by the editor I was using. BUT I am here to find a tool that would tell me about such errors.
A: 

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

pritaeas
A: 

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.

Ross
A: 

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.

Jordy
@Jordy - indent your code-blocks by 4 spaces to get the goodness of syntax highlighting. Code blocks interpret newlines in your source as a new line in the output.
Dominic Rodger
Done, 'text to fill commentbox'
Jordy
The error shown with this method : Parse error: syntax error, unexpected $end in E:\UniServer\www\content.php on line 27 . not exactly accurate...
Don't forget to add the <?php open tag + ?> close tag.
Jordy
+2  A: 

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.

Dominic Rodger
THanks . i had no idea about this. will explore this option.
I still get a blank page, even after editing my php.ini
@user161179 - did you restart Apache?
Dominic Rodger
A: 

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

php -l myscript.php

jay.lee