OOP Intricacies

Static properties are inherited, but in order to use them “intuitively”, you need to use the, erm, static keyword. E.g.:

class sync_message {

    var $message;
    var $datetime;
    public static $filename = 'synchronizer.log';

    function write_log() {
        // simplified example
        $handle = fopen(static::$filename);

class sync_warning {
   public static $filename = 'warnings.log';

So, in order to have sync_warning use the file name warnings.log, you need to use static::$filename. And not, as you might expect, the keyword self. The self keyword does a lookup in the class where the method which uses the static variable was originally defined.

Profiling a PHP Application with Xdebug

Install xdebug and kcachegrind through apt-get or something similar.

Now put this in your php.ini (usually '/etc/php5/apache2/php.ini'):

;; Make sure that xdebug has read/write access in the following dirs:
; trigger is GET or POST variable XDEBUG_PROFILE
; %s = full path, %p = process id, %H = $_SERVER['HTTP_HOST']
;xdebug.profiler_output_name ="cachegrind.out.%H.%p"
xdebug.profiler_output_name ="cachegrind.out.%s.%p"

View the output of xdebug (written to /home/onno/php/xdebug in this example) in kcachegrind.


While using MySql version 5.0.7 or higher you will encounter a bug in moodle 2.0 or lower. This error occures in the Assignment module.

BIGINT UNSIGNED value is out of range in '(`spring`.`s`.`timemarked` - `spring`.`s`.`timemodified`)'

To fix this you have to replace the following line in the assignment/lib.php file:

COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';


COALESCE(SIGN(CAST(s.timemarked as SIGNED) + SIGN(CAST(s.timemarked as SIGNED) - CAST(s.timemodified as SIGNED))), 0) AS status ';

Use a search and replace tool, the line that has to be replaced is in this document twice, by default.


Tool to create API documentation, based on inline comments. Type phpdoc -h to get help. Visit this Quickstart to get more info (but be warned: the documentation for phpdoc is very wordy).


This worked for me under Ubuntu (10.04 LTS - the Lucid Lynx):

sudo pear install PhpDocumentor


phpdoc -t docs -d . -s on -dn Soda
  • -t: target directory where docs are placed
  • -d: directory to look for source code
  • -s: include source code (default: off)
  • -dn: defaultpackagename (here: Soda - this only works if each of your source files contains a directive @package Soda at the top)

Please note that you style the first page of your API documentation with a 'tutorial'. phpDocumentor needs the tutorials in a very specific place: soda/tutorials/Soda/Soda.pkg, where soda is the same dir as the one mentioned under -d.

Here's a sample tutorial:

<refentry id="{@id}">
  <refname>Soda API Documentation</refname>
    Soda is a Moodle module to develop new modules. These web pages contain the API documentation for Soda's classes.
    A basic tutorial for Soda is located here: {@link} (use right-click to open in new tab or window).
    Copyright (C) 2011 Solin -
    Programming and development:
    Onno Schuit (

Personal Tools