Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am coming from .NET to PHP. I am playing around with a long file written by someone else (called "cryptographp.inc.php"). It builds and returns an image to the browser.

I want to show the image that the file returns on my Cryptocode/index.php page--like this:

<?php
include './cryptographp.inc.php'; 
?>

But when I load the page, firefox returns an error saying

"The image http://localhost/Cryptocode cannot be displayed because it
contains errors"

How would I go about debugging an error like this in PHP? I am used to stepping through code in visual studio. What techniques would people use in the PHP world?

share|improve this question

1 Answer

In short: I would start by enabling my development environment to catch the errors. There are some setting you would need to set.

For the syntax errors, you need to enable error display in the php.ini. By default these are turned off because you don't want a customer seeing the error messages. Check this page in the PHP documentation for information on the 2 directives: error_reporting and display_errors. display_errors is probably the one you want to change. If you can't modify the php.ini, you can also add the following lines to an .htaccess file:

php_flag  display_errors        on
php_value error_reporting       2039

You may want to consider using the value of E_ALL (as mentioned by Gumbo) for your version of PHP for error_reporing to get all of the errors. more info

Three important points to consider:

  1. Check the error log file as it will have all of the errors (unless logging has been disabled).

  2. Adding the following 2 lines will help to debug errors that are not syntax errors:

    error_reporting(-1); ini_set('display_errors', 'On');

  3. Use an editor that checks for errors why you type, such as PhpEd. It also comes with a debugger which can provide more detailed information. (The PhpEd debugger is very similar to xdebug and integrates directly into the editor so you use one program to do everything). The "xdebug" will make your reports much nicer as well.

Cartman's link also has very good guidelines to follow: http://www.ibm.com/developerworks/library/os-debug/

References and blog posts:

share|improve this answer
4  
Another good IDE to use for PHP develoment is PHPStorm by JetBrains. It has syntax highlighting and checking, auto-completion, debug features (including an interface with xdebug) etc. I have no connection with the company, just a happy customer for several years. –  tcrosley Aug 20 at 22:21
 
you might want to set the error_reporting value in htaccess/apache to 2147483647 - it's a bitmask, and the exact flags change between different versions of PHP –  HorusKol Aug 21 at 5:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.