Log in

View Full Version : Debugging Techniques



marain
05-13-2012, 01:10 PM
What follows (until the line of asterisks) I have copied and pasted from http://php.syntaxerrors.info/index.php?title=Debugging


Debugging
From Php
Jump to: navigation, search

Many hosting providers have error reporting switched off by default, and users cannot change the configuration. You can check the settings for your host using phpinfo() as follows.

<?php
phpinfo();
?>

In the case where error reporting isn't given automatically, accessing the PHP page in your browser displays a blank page. However, you can still debug the code and see what the syntax error is by creating a separate PHP file and including the code which is failing, as follows.

<?php
ini_set( 'error_reporting', E_ALL );
ini_set( 'display_errors',TRUE );
include "image.php";
?>

Note: The messages will be displayed back to the browser, so this method shouldn't be used for pages that the user will see.
.
.
.
* This page was last modified on 3 August 2008, at 19:45.
* This page has been accessed 2,690 times.
* Content is available under Attribution 3.0 .
* Privacy policy
* About Php
* Disclaimers

********************************************************

I am understanding the line...

include "image.php";

...to be calling for the programmer to insert the name of the wayward page in place of "image.php". e.g., include "test.php"; When I make this substitution, however, I get no error messages. Instead, the browser simply attempts to actually run the errant page. It doesn't run, of course, on account of the syntax error that I am trying to track down in the first place.

Is http://php.syntaxerrors.info/index.php?title=Debugging wrong? Or am I misinterpreting it? (If the latter, then the instructions are not idiot-proof!)

A.

traq
05-13-2012, 04:39 PM
<?php
ini_set( 'error_reporting', E_ALL );
ini_set( 'display_errors',TRUE );
Note: The messages will be displayed back to the browser, so this method shouldn't be used for pages that the user will see.
Is http://php.syntaxerrors.info/index.php?title=Debugging wrong?
Well, not really... though it is over-simplified and misleading.

The reason this won't work if you're dealing with a syntax error is that this is a problem that is found when the script is interpreted (e.g., when PHP is preparing the code, not when the code is run). When there are syntax errors, the script is never actually run, and your ini_set() call is never executed.

So: the snippet above will only catch runtime errors.

If you're using a good code editor, it should include syntax highlighting, which is a great help in tracking down problems like this.

Also, do I understand correctly that your host is suppressing all error messages (so, when you run your script, you see only a blank page, and no error message at all)? Did you check your phpinfo() as suggested?

You might be able to change the error_reporting setting in your php.ini file, but some hosts disallow users access there too. Another option would be to install php on your own machine, and develop locally (which is actually a fantastic thing to do regardless).

marain
05-13-2012, 08:56 PM
My host does allow me to change php.ini parameters. Unfortunately, when I do so, phpinfo.php continues to reflect the original php.ini values. I am in dialogue with my host now, trying to resolve this confusion.

traq
05-13-2012, 09:21 PM
; this is your php.ini file
error_reporting = E_ALL & E_NOTICE & E_STRICT
display_errors = Onright?

if you don't mind sharing, what host you are using?