1. If you update to Joomla 3.8.10, please make sure that you either do a full GitHub update of Fabrik, or disable caching for your lists (in the Advanced settings) or turn off Joomla's System Cache setting. A change in Joomla's cache code in 3.8.10 required a fix in Fabrik, which will be rolled in to the next release, but is currently only available in GitHub.
    Dismiss Notice
  2. We will be performing an update of XenForo (the forum software use on this site) this afternoon, Fri 8/17/2018. The forums will be unavailable for a (hopefully!) short time.
    Dismiss Notice

Debugging

May 7, 2018
Debugging
  • There are several ways you can debug your php code depending on the issues you are having. Most of the methods below will display a string, so you also need to know how to convert arrays and objects to strings in order to display them.


    Converting other types of data to strings(top)


    Converting an array to a string(top)

    PHP:
    $string = json_encode($array);

    Converting an object to a string(top)

    Assumiong that your object implements a __toString() function:
    PHP:
    $string = (string) $object;

    PHP echo(top)

    The most obvious way to output debugging information is to use the php "echo" statement. However, this is not always as straightforward as you might think because the output will often appear somewhere in your HTML which may not be immediately obvious or even visible, but can sometimes be missing altogether if you outputted it during a php output buffer capture ("ob_start"):
    PHP:
    echo "$string = " .  $string;
    You may need to use your browser's Developer's Tools to search for the output.

    You also need to be aware that if page headers are still being created, your output will terminate these and may create other output oddities.

    Joomla's standard message area(top)

    Possibly the easiest way to put a debug message on screen is to send it to Joomla's standard message area:
    PHP:
    JFactory::getApplication()->enqueueMessage($string, 'message');

    Fabrik's debugging infrastructure(top)

    If you want to leave debugging code permanently in your php, then you can use Fabrik's own debugging system.

    Turning on Fabrik's debugging system(top)

    To view additional debug output showing what Fabrik is doing, you need to do two things:
    1. Set 'allow fabrik debug' to either 'Yes' or 'Debug JS' in Fabrik's global parameters.
    2. Add to the end of the URL the following string:
      Code (Text):
      &fabrikdebug=1
      or
      Code (Text):
      ?fabrikdebug=1
      if there are no query parameters in the URL already.

    Permanent debugging statements(top)

    To display your own debugging information alongside Fabrik's, use:
    PHP:
    FabrikHelperHTML::debug($string, 'debug:heading');

    Browser Developer's Tools(top)

    To get debugging information when the output is being sent in response to an Ajax call for e.g. field or form validation or for calc elements, and is not immediately visible the browser window.

    You can use the following methods :

    Use your browser's Developer's Tools(top)

    To display variables, you can use the PHP var_dump() function :
    PHP:
    var_dump("MY_VAR : ",$my_var);
    exit;
    When the , this will stop the execution of the plugin and you will get the following error on your form :
    SyntaxError: JSON.parse: unexpected character

    For example in Firefox's Developer's Tools / Firebug, in the Javascript Console you will see a POST with:
    Click on the '+' symbol before "POST". You will see a new menu, by default on "Response" tab. Click on "HTML" tab, you will see your dump in a more visible way.

    If you want to display many variables, you can write :
    PHP:
    echo "found : " . $found . "\n";
    echo "status : " . $status; exit;
    The "\n" is to display the next variable on a new line.
    And don't forget to write "exit;" on the last line !

    http://screencast.com/t/1lPY94LRQdsD

    Joomla JDump extension(top)

    JDump allows you to display your debugging output in a popup window, without stopping the execution of your code. Just insert in your code something like:
    PHP:
    dump($variable, 'Variable Name');
    In case if you get the following error at the backend of Joomla after installing JDump:
    Code (Text):
    Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; plgSystemDump has a deprecated constructor in /home/
    Replace this code:
    Code (Text):
    function plgSystemDump(& $subject, $params) {
            parent::__construct($subject, $params);
    with
    Code (Text):
    function __construct(& $subject, $params) {
       parent::__construct($subject, $params);
    in /plugins/system/dump/dump.php on lines 27 / 28

    See also...(top)

    https://docs.joomla.org/How_to_debug_your_code
    https://www.joomlabeginner.com/blog/tutorials/59-how-to-use-joomla-debug-system