Methods of Debugging - PHP

Author - Umang Pasricha
1 Comment

Methods of Debugging by dumping information

These methods are used for debugging in PHP. We can see the variable values in human-readable form on the console and can find errors in case there are issues due to variables incorrect values. print_r() and var_dump() are used in core PHP as well as its Framework. dd() is newly introduced in Laravel.

  1. print_r():
    This command gives the human-readable information about a variable.

    		$variable = Account::all();

    In the above example, die() will stop executing a further line of code. This will give us structured output as shown below-

  2. var_dump():
    This command also gives readable information but in a nonstructured manner.

    		$variable = Account::all();

    Similarly, as print_r() example, this also gives output in the console and stops further execution. The output is not properly readable. Here is the output that you will see-

  3. dd():
    Here ‘dd’ stands for “Dump and Die”. This means it will give the variable value and stop executing further code. We do not have to explicitly write die() command.

    	       $variable = Account::all();

    This will also give us information in the form of collection and we have to open each sub-collections to see each value.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

One response on “Methods of Debugging – PHP

  1. […] the connection to your device. If your device is showing up as Unknown, accept the Allow USB Debugging permission prompt on your Android Mobile. After enabling USB […]

Leave a Reply

Your email address will not be published.