PHP debugging

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.
Locked
joatmon
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Thu Nov 10, 2005 8:54 pm

PHP debugging

Post by joatmon » Fri Aug 22, 2008 2:13 pm

There was an awesome instructional page written by ianmac regarding debugging PHP code on Eclipse, but it appears to have disappeared. Is there a new URL for this page ianmac? Or did you take it down permanently. I hope not because it was a great resource and helped me out tremendously.

thanks!

Gergo Erdosi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4031
Joined: Sat Nov 11, 2006 9:34 pm
Location: Hungary

Re: PHP debugging

Post by Gergo Erdosi » Fri Aug 22, 2008 7:47 pm


joatmon
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Thu Nov 10, 2005 8:54 pm

Re: PHP debugging

Post by joatmon » Sat Aug 23, 2008 7:32 pm

Very nice. Thanks!

User avatar
chaosprime
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Mon Aug 25, 2008 6:17 pm
Location: New Jersey

Re: PHP debugging

Post by chaosprime » Mon Aug 25, 2008 6:41 pm

Just because I try to make this available to anyone who might care: you might get some mileage out of this snippet that makes PHP produce stack traces on errors and warnings, instead of useless final-location-only errors:

Code: Select all

<?php
function process_error_backtrace($errno, $errstr, $errfile, $errline, $errcontext) {
    if(!(error_reporting() & $errno))
        return;
    switch($errno) {
    case E_WARNING      :
    case E_USER_WARNING :
    case E_STRICT       :
    case E_NOTICE       :
    case E_USER_NOTICE  :
        $type = 'warning';
        $fatal = false;
        break;
    default             :
        $type = 'fatal error';
        $fatal = true;
        break;
    }
    if(php_sapi_name() == 'cli') {
        echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
        foreach(array_reverse(debug_backtrace()) as $item)
            echo '  ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n";
    } else {
        echo '<p class="error_backtrace">' . "\n";
        echo '  Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
        echo '  <ol>' . "\n";
        foreach(array_reverse(debug_backtrace()) as $item)
            echo '    <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n";
        echo '  </ol>' . "\n";
        echo '</p>' . "\n";
    }
    if($fatal)
        exit(1);
}

set_error_handler('process_error_backtrace');
?>
Chaos
Lost Souls: text based RPG
MUDseek: MUD games search


Locked

Return to “Joomla! Coding 101”