Advanced Search

Results 1 to 4 of 4

Thread: Debugging Techniques

  1. #1
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    130
    Thanks
    49
    Thanked 0 Times in 0 Posts

    Default Debugging Techniques

    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.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,629
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by marain View Post
    Quote Originally Posted by php.syntaxerrors.info
    PHP Code:
    <?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).
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #3
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    130
    Thanks
    49
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,629
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Code:
    ; this is your php.ini file
    error_reporting = E_ALL & E_NOTICE & E_STRICT
    display_errors = On
    right?

    if you don't mind sharing, what host you are using?
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •