• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debuging in PHP

How the debugging techniques are in use by everyone for PHP and CI. I ran across an issue and ended up using some odd techniques myself.

Here is what I have done so far:

1. Added echo statements at certain points to see if the code was being called (if(..) statements, etc.)
2. Enabled error logging in CI
3. Commented out the set_error_handler(..) call in Front_controller.php so I could see the entire error message with line #‘s included.

Any other good ways to debug stuff in PHP and/or CI?

I really miss breakpoints and stepping through code as it runs….

in index.php you have to print error_reporting(E_ALL); which is show all the error.

I HATE breakpoints and stepping through code as it runs. I LOVE your numbers 1,2, and 3!

It sounds like you're new to scripting. After a while you get used to it and eventually (if you're like me) you learn to prefer it. Don't be discouraged, stick with it. Good luck.

P.S. There are some IDEs for PHP that allow you to set breakpoints and step through your code, although I can't recommend one as I've never used one.

>>> Any other good ways to debug stuff in PHP and/or CI?

error_reporting(E_ALL | E_STRICT);
  date_default_timezone_set('Asia/Krasnoyarsk'); // Bangkok time
  define('LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME']);
  define('BR', '<br />');

  function fred($msg=array('one', 'two', 'three'), $msg_name='$msg_name not passed') {
  echo "<pre style='text-align:left;background:#ffc none;color:#000;text-align:left'>";

        echo '<b>' .$msg_name .'</b> ==> <span>';
                echo BR;
        echo "</span></pre>";


Code usage: // can be in controllers, views, models, libraries, etc
    echo BR .'None of this is shown online';

    $atest = array('one', 'two', 'three');
    fred($atest, '$atest');

>>> Any other good ways to debug stuff in PHP and/or CI?
1. Always inherit a master controller]
2. define some common public $debug variables in the master controller

Display that does not screw up page formatting
// in controllers, views, etc
$this->debug = 'this is a test to see if it works';

// view
echo "<div style='clear:both;width:96%;margin:1em auto;border:solid 1px;overflow:auto'>";
   echo BR .$this->debug_001;
   echo BR .$this->debug_002;
   echo BR .$this->debug_003;
   echo BR .$this->debug_004;
echo '</div>/';


I installed xdebug on my development machine. I find its output useful.

It provides profiling, stack traces, and nice colorful output for var_dump... I'm not even using it to it's full potential yet.

I've yet to use it, but you might find Firebug with FirePHP useful. '

The wiki has some instructions on setting up / using FirePHP in CI. It might be a good choice instead of echoing out values when tracing your variables.

I too use xdebug but what's wrong with:


It will 'set' a breakpoint. There is only so much code that gets processed and you can usually narrow it down to a particular function/method or variable/property/object/array.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.