Scriptcase Experts

Simple way to debug your variables in Scriptcase

19 May, 2016

As you all know, var_dump() and print_r() are usefull PHP functions to gather information of variables, but sometimes, you need to track a lot of data and is usefull to save on disk.

Here I share a simple but usefull method to save on disk variables values. With this way, later you can see this file from browser (usefull for remote instances of projects).

function debugHTML($someVar, $texto){
 $fichero = fopen("../kodebug.html", "a");
 ob_start();
 var_dump($someVar);
 $result = ob_get_clean();
 $hoy = date("H:i:s"); 
 fwrite ($fichero, '<br>');
 fwrite ($fichero, '<strong>['.$hoy.'] ' . $texto . '</strong><br> <font color="red">' . $result. '</font><br><br>');
 fclose($fichero);
}

Just paste this on an internal lib, and when you need to use it, include your internal, and write when needed:

debugHTML(yourvariable, text_to_identify);

Now, you can call kodebug.html (one up level from your app, root of project) from your browser

For example, we will write the code on an application called  blank_debug, under a project called tests.

20160519 10_10-screen00018520160519 10_04-screen000184

 

20160519 10_11-screen000186

Now, my blank app was executed and the file was generated. You can acces this log file from browser one level up.

20160519 10_11-screen000187

debugHTML() adds to the end of the file, is not overwrited. If you need to clean it, just delete kodebug.html file.

Enjoy.

 

The following two tabs change content below.
kofundador y konsultor en KomencoIT, con una trayectoria de más de 14 años de experiencia en el sector TIC. Especialista en proyectos llave en mano, outsourcing y asesoramiento sobre nuevas tecnologías. ScriptCase Certified Partner/Developer/Mentor.

Latest posts by Giuseppe (see all)

2 Responses to Simple way to debug your variables in Scriptcase

  • Giuseppe – I like your insight. The only suggestion I would have is to keep all Var’s in English. It would be much more helpful to all. Do not make a mistake NetMake did puting lots of strings in Portugese which most people do not understand. I’m looking for more tutorials – you doing great job. Thank you.

    • Hey Arthur, lot of time without news from you.
      Yes, didn’t noticed about. I creatd this function for internal use, then I just didn’t changed when published. Just change all occurrences of:
      $texto -> $text
      $fichero -> $file
      $hoy -> $today

      Regards.

Leave a Reply