PHP errors

Why I can't see any php error when I'm developing a plugin? When an error happens I see just a white screen.

Anybody knows?

 

  • Others share your pain.  Exceptions get handled by an installed error handler, which pipes them to the server log, but syntax errors disappear and leave you with a blank screen.  More than once I've had a stray character bring down the whole system.

    I don't understand why a simple php page spits its syntax errors to the server log but elgg does not.

  • > I don't understand why a simple php page spits its syntax errors to the server log but elgg does not.

    Hi Timothy,

    In my experience, this is a PHP limitation, not an Elgg limitation. PHP always returns blank pages when there is a syntax error so far as I know.

    Most PHP devekopers use an IDE that highlights syntax errors well before the code is put on the server (or even saved). I use Eclipse PDT.

  • does it always Kevin?

    if its a syntax error, it usually does throw an error. e.g leave out a smicolon or use more variables than required by a function.

    if the problem is in the semantics like an expected result not being returned by a function because of a flaw in your logic, then one would have to trace through the code line by line...maybe eliminating by commenting

  • It's not the blank page, it's the fact that the error doesn't show up in the log.  Something happens in the processing of elgg code that results in the syntax errors no longer showing up in the server log.

     

    I know I *really* need to get eclipse set up for PHP, but haven't done so yet (I have a heavily customized Java setup that doesn't play well with other targeted environments).

  • Here's a solution I'm using...

    Edit .htaccess in the root directory of your Elgg installation.

    Find

        php_value display_errors 0

    and change it to

        php_value display_errors 1

    Now PHP errors will be displayed in the browser window instead of the blank screen.  Tested in Elgg 1.1 running on Linux, Apache 2, PHP 5.2.0.

    NB. This is only for your development environment - don't use on a production server!

     

  • Thanks to some input from Kevin, I've managed to capture the most common errors by removing the "@" from the includes in engine/lib/elgglib.php:elgg_view.  That will allow syntax and other errors to show up in the server log as they normally do.

  • Just to correct some misinformation I posted above (sorry about that), I believe that PHP returns a blank page for syntax errors if a custom error handler has been defined, which is the case for Elgg.

    You can comment out the custom error handler (when debugging your code)  in engine/start.php

    As Tim points out (following some advice from Rolando Espinoza La Fuente here:

    http://groups.google.com/group/elgg-development/browse_thread/thread/8b32a18d09cb81b3

    ), you may also need to move some @s in various places to get errors to display.

    I was hoping to rewrite the custom error handler to display syntax errors, but according to Cash's comment in the same thread, that appears to be impossible.

    So I'm going to continue to depend upon Eclipse to find my syntax errors.

  • I posted a bug on this, which was quickly addressed by CurveRider.  They've at least addressed the @include issue in what elgg_view includes, which should help in a lot of cases.

    Note that it's not only syntax errors, but also things like attempting to index a non-array (something I'm encountering a lot with some web services that return multiple types of values (e.g. "false" instead of an empty array, or one object instead of an array of size one).