php best debugging functions

Solutions on MaxInterview for php best debugging functions by the best coders in the world

showing results for - "php best debugging functions"
Ana Paula
23 Nov 2019
1
2I am using two ways to debug code
3
4one is print the data and die the function in specific point.
5 
6     print_r($data);die;
7
8second one is writing log file in specific point in code.
9
10function write_log($log_msg)
11{
12    $log_filename = "logs";
13    if (!file_exists($log_filename)) 
14    {
15        mkdir($log_filename, 0777, true);
16    }
17    $log_file_data = $log_filename.'/debug.log';
18  file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
19    
20} 
21
22write_log("Writing Log");
23$a = array(
24        array('id' => '1','date' => '09-04-2018','length' => '10'),
25        array('id' => '2','date' => '09-04-2018','length' => '20'),
26        array('id' => '1','date' => '10-04-2018','length' => '11')
27    );
28write_log(print_r($a,1));
29
Michele
27 May 2020
1
2I find it very useful to print out to the browsers console instead of just var_dumping:
3
4function console_log( $data ){
5  echo '<script>';
6  echo 'console.log('. json_encode( $data ) .')';
7  echo '</script>';
8}
9
10Usage:
11$myvar = array(1,2,3);
12console_log( $myvar ); // [1,2,3]
13
Francesco
12 Jan 2019
1<?php
2$myVar = "hello world!";
3
4var_dump($myVar);
5print_r($myVar);
6
7$allVars = get_defined_vars();
8print_r($allVars);
9debug_zval_dump($allVars);
10
11function sayHello($hello) {
12    echo $hello;
13    debug_print_backtrace();
14}
15
16sayHello($myVar);
17?>
Michael
11 Nov 2017
1
2A good example of data output to the console via <script> tags, I myself used this first, but he broke the captcha job, because <script> tags were inserted into the base64 code of the captcha picture. Then I began to display logs in the headers with such a function (it may help someone else, in a similar situation):
3
4<?php
5
6function header_log($data){
7  $bt = debug_backtrace();
8  $caller = array_shift($bt);
9  $line = $caller['line'];
10  $file = array_pop(explode('/', $caller['file']));
11  header('log_'.$file.'_'.$caller['line'].': '.json_encode($data));
12}
13
14?>
15
16Usage:
17$myvar = array(1,2,3);
18header_log( $myvar ); // in headers we see: log_filename_rownumber: [1,2,3]
19
queries leading to this page
php best debugging techniqueshow to break point in phpphp script debuggingphp debugpdebugging phpdebugging phpphp debug functioncan you debug phpdebugging meaning in phpphp in debug modephp debug add inline debugger not workingphp define 28 27debugphp tracy debuggerdebugging php functionvs php debuggerdebugging php codeset page level debug in phpstep debugger not working phpfungsi debugging phpphp debuggersbest debugger for phpphp debug set debuggerdebug phpdebugger phpdebug mode in phpdebug application in core phpdebug php code stepphp debug only oututdebugging php in elemantordebuyg phpphp debuggerdebugging steps phpuse debugger php php function to debugginghow to do debugging in phphow to get a debugger in phpdebugging in phplearn debug in phphow to easily debug php how to debug php filedebugging php on apachehow to debug php codephp roy debuggingwhich of the following statements correctly describe methods for debugging php codephp manual debuging techniqueweb debugger phpdebougger phpphp debugging a functionphp update code while debuggingdebug app phpmethods for debuggin php codephp debugging codephp debuggingphp int debug pathphp debugging logphp debufgingbest php debuggercore php debughow to trace if debug switch in phpphp best debugging functionsdebugging phpstoemhow to debug in phpdebug php line by linehow to test debug on php codedebuging php functionphp best debuggerimplement a php debugging systemdebugger in phpwhy doesnt php have a good way to debugdebug php codedebugging php programshow to debug php using developer toolswhat function is calling a function php debugphp debug only outputphp debugerphp debugging techniquesphp best debugging functions