Actions

Debugging: Difference between revisions

From LimeSurvey Manual

m (Reverted edits by Tuncerd (talk) to last revision by DenisChenu)
Tag: Rollback
mNo edit summary
Line 10: Line 10:
<syntaxhighlight lang="php" enclose="div">$variable = $this->someMethod();  // What would this return?
<syntaxhighlight lang="php" enclose="div">$variable = $this->someMethod();  // What would this return?


Yii<center>trace(CVarDumper</center>dumpAsString($variable), 'vardump');</syntaxhighlight>
Yii::trace(CVarDumper:dumpAsString($variable), 'vardump');</syntaxhighlight>


We make use of the <nowiki>Yii<center>trace()</nowiki> method, and pass it the result of the static call to <nowiki>CVarDumper</center>dumpAsString()</nowiki>. What it does is is similar to var_dump but it allows a little more control if you need if. The second parameter 'vardump' makes sure our messages gets logged. All this is a lot of typing and since programmers are lazy, we created a global function to save you some trouble. Instead of the lines above you can also use:
We make use of the <nowiki>Yii<center>trace()</nowiki> method, and pass it the result of the static call to <nowiki>CVarDumper</center>dumpAsString()</nowiki>. What it does is is similar to var_dump but it allows a little more control if you need if. The second parameter 'vardump' makes sure our messages gets logged. All this is a lot of typing and since programmers are lazy, we created a global function to save you some trouble. Instead of the lines above you can also use:

Revision as of 19:03, 11 March 2019

Debugging

Working with a framework can sometimes be hard to debug. In Yii we have some tools at our disposal to help debug the application. The very first thing to do is modify application/config.php and to set debug = 2 at the end. Now we get more errors presented and we can use a trace function to see what a variable's content is at any time during program execution.

If you want to see what queries are sent to the database, you can also enable debugsql by setting it to 1.

To do a dump of a variable you can use the following syntax:

$variable = $this->someMethod();  // What would this return?

Yii::trace(CVarDumper:dumpAsString($variable), 'vardump');

We make use of the Yii<center>trace() method, and pass it the result of the static call to CVarDumper</center>dumpAsString(). What it does is is similar to var_dump but it allows a little more control if you need if. The second parameter 'vardump' makes sure our messages gets logged. All this is a lot of typing and since programmers are lazy, we created a global function to save you some trouble. Instead of the lines above you can also use:

traceVar($variable);

As a bonus you will also get the file and line that called the traceVar function to assist in debugging.