We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3496
    • 101 Posts
    I’m writing some PHP code within a MODx environment at the moment - and I’m working on a PHP class that could be useful for other people too (so I will probably try to make a package out of it in the future), but I’m still rather new in PHP and MODx, so I still have some issues to sort out, among which the following:
    - how to catch and report errors
    - how to collect and show debugging information

    For errors:
    Would the "try...catch" approach be the right one to follow?
    What would be the right way to get errors to the end-users? (return as result of snippet-call?)
    What would be the right way to deliver more detailed/technical error-information? (use modx->log()? - is there more information available about the MODx Revolution logging?)

    For debug-information:
    Currently I’m using FirePHP - with this I can get debug information in the firebug console.
    Is that a good approach?
    If not; what would be a better/saver way?

    Any help would be appreciated...
      • 22303 MODX Staff
      • 10,725 Posts
      modErrorHandler is registered by the modX class as the default error_handler, but this is configurable, so you can provide your own error handling class in your configuration (per config, context, and/or user).

      Also, modX::log() can direct it’s log messages to various logTargets (by default it goes to the error.log file in core/cache/logs (which is accessible from Reports -> Error Log).

      For now there is no Exception handler in Revolution, but we are working towards this, likely for a 2.1 release.

      Using FirePHP may work for you, though I’ve never used it. Perhaps you can implement a modFirePHPErrorHandler class and see what can be done...
        • 3496
        • 101 Posts
        Thanks; that should be enough information to get me started!
          • 3496
          • 101 Posts
          In case other people want to use this, I’m now currently using the following:

          To report errors to the MODx error log:
          trigger_error('...', E_USER_ERROR);

          To report warnings to the MODx error log:
          trigger_error('...', E_USER_WARNING);

          To sent debug information to the MODx error log:
          $modx->log(modX::LOG_LEVEL_DEBUG, '...');

          The MODx error log can be found in the MODx manager->Reports->Errorlog.

          To get the debug and error output use statements like the following:
          $modx->setDebug(E_ALL & ~E_NOTICE); // sets error_reporting to everything except NOTICE remarks
          $modx->setLogLevel(modX::LOG_LEVEL_DEBUG);