Monday 8 July 2013

Code Completion with Magic Methods

Recently I was told that a code example that used the "__call" didn't work. As he couldn't call the function I had outlined outside of my example code?

Weird!!

This was down to eclipse's  auto-completion only listing the functions that are declared in the class source.. and on paper that seems normal. 
Unfortunately when dealing with a dynamic type language like PHP this won't cut it!

So how can we address for our auto-completion and document generation friends?

Example time: (the below is straight from the PHPDocs)

/**
 * show off @method
 *
 * @method int borp() borp(int $int1, int $int2) multiply two integers
 */
class Magician
{
    function __call($method, $params)
    {
        if ($method == 'borp') {
            if (count($params) == 2) {
                return $params[0] * $params[1];

            }
        }
    }
}
... continue reading!