Welcome Guest, Not a member yet? Register   Sign In
Debuging in PHP
#1

[eluser]Unknown[/eluser]
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….
#2

[eluser]gomji9star[/eluser]
in index.php you have to print error_reporting(E_ALL); which is show all the error.
#3

[eluser]slowgary[/eluser]
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.
#4

[eluser]John_Betong[/eluser]
 
>>> Any other good ways to debug stuff in PHP and/or CI?
 

index.php
Code:
error_reporting(E_ALL | E_STRICT);
  ini_set('display_errors','On');
  
  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>';
                print_r($msg);
                echo BR;
        echo "</span></pre>";

  }//endfunc


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

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

[eluser]John_Betong[/eluser]
&nbsp;
>>> Any other good ways to debug stuff in PHP and/or CI?
&nbsp;
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
Code:
// in controllers, views, etc
$this->debug = 'this is a test to see if it works';

// view
&lt;?php
if (LOCALAHOST)
{
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>/';
}
?&gt;

&lt;body&gt;
&lt;/html&gt;
&nbsp;
&nbsp;
#6

[eluser]Natebot[/eluser]
I installed xdebug on my development machine. I find its output useful.
http://www.xdebug.org/

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. '
http://www.firephp.org/

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.
#7

[eluser]n0xie[/eluser]
I too use xdebug but what's wrong with:

Code:
var_dump($some_array_or_object);
exit();

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.




Theme © iAndrew 2016 - Forum software by © MyBB