RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About Me
  • My Publications
  • My Work Domain
  • phpResource Feeds
  •  

    Which One is Better?

    See two debugging functions:

    ———————1st One—————————

    function dBug($dump)
    {
    print "<pre>";
    var_dump($dump);
    print "</pre>";
    }

    ———————————————————-
    This one gives debug-data along with datatypes and lengths.

    —————————2nd One———————–

    function dBug($dump)
    {
    print "<pre>";
    print_r($dump);
    print "</pre>";
    }

    ———————————————————–
    This one gives debug-data in a formatted way.

    Here’s an example:


    $myname = array(
    'last_name' =>'Razzaque',
    'first_name' =>'MA',
    'nick_name' =>'Rupom'
    );

    Result of the first dBug():

    array(3) {
    ["last_name"]=>
    string(8) "Razzaque"
    ["first_name"]=>
    string(2) "MA"
    ["nick_name"]=>
    string(5) "Rupom"
    }

    Result of the second dBug():

    Array
    (
    [last_name] => Razzaque
    [first_name] => MA
    [nick_name] => Rupom
    )

    The second dBug() gives more readable debug-data than that of the first one. But the first dBug() is more informative than the second one. So friends, which one should we choose?

    Usually I use second one for a more readable debug-data.
    [Rupom]

    5 Responses to “Which One is Better?”

    1. Md. Riyadh Hossain Says:

      Generally I am used to with second one for debugging purpose. I think first one will be helpful for debugging with large and complex data.

    2. Rupom Says:

      Thanks for your comment.

    3. NHM Tanveer Hossain Khan (Hasan) Says:

      It depends on different requirement …

      When i want to chkout only the value and property i use print_r
      for more info like length of array and type i will use var_dump…

      Though this are too handy try to use log4php… and use file appender so your debug output will be available in local file which u can chkout offline…

      Thank u wish you best…

    4. Rupom Says:

      Thanks Hasan. The actual thing is requirement. Which one will be used depends on requirements. You are right.

      Wish you all the best….

    5. Anonymous Coward Says:

      [code]
      function dBug($dump)
      {
      print “”;
      print_r(var_dump($dump));
      print “”;
      }
      [/code]

    Leave a Reply

    You must be logged in to post a comment.