Archive for the 'PHP' Category

PHP5 Certification Announced

Thursday, 14th September, 2006

Somewhat late (just like me posting this news) but Zend have finally announced PHP5 certification. I purchased my voucher 3 months ago, now all I need is the study guide to materialise!

PHP4 Exceptions

Sunday, 10th September, 2006

During the last project I worked on, before moving companies, I would often want to pass back more error information from methods than primitive types would allow. What I wanted was a PHP4 exception. You’ll need PHP 4.3.0 or above for this class to work.

class Error {

    var $message;
    var $code;
    var $file;
    var $line;
    var $trace;

    function Error($message = null, $code = 0) {

        $this->message  = $message;
        $this->code     = $code;
        $this->trace    = (phpversion() >= 4.3) ? debug_backtrace() : array();

    }

    function getMessage() {

        return $this->message;

    }

    function getCode() {

        return $this->code;

    }

    function getFile() {

        return $this->trace['file'];

    }

    function getLine() {

        return $this->trace['line'];

    }

    function getTrace() {

        reset($this->trace);
        return current($this->trace);

    }

    function getArgs() {

        reset($this->trace);
        $trace = current($this->trace);
        return $trace['args'];

    }

}

I then created the following function to identify when the Error class was returned:

function isError($result) {

    return (is_a($result,'Error') ? true : false);

}

I would then use it like so:

class OrderDB {

    ...

    function save() {

        if (!$this->db->query(
            'UPDATE orders SET ... WHERE order_id = ' . $this->order->getId())) {
            return new Error('Failed to update order ' . $this->order->getId());
        } else {
            return true;
        }

    }

    ...

}

Mimicking a try catch block:

$saveResult = $orderDb->save();

if ($saveResult) {
    ...
} else if (isError($saveResult)) {
    $logger = $this->locator->get('log');
    $logger->log('Error occured in ' . $saveResult->getFile() . ' on line ' . $saveResult->getLine() . ': ' . $saveResult->getMessage());
    ...
}

An obvious short coming of this solution is that every result must be checked whereas a true try catch statement will catch any exception thrown within the try block. On the plus side you can still extend the Error class and isError will recognise you’ve returned a child of the Error class.

Typically 2 minutes Googling reveals a beefed up PHP4 exception class.

PHP 5 Certification Announced

Thursday, 27th July, 2006

Zend have finally posted some information about their new PHP5 certification. This new certification was planned to be released yesterday but has been postponed now until the end of August/early Sept.

There’s a fairly comprehensive list of topics – hopefully it’ll be a more worthwhile qualification than the original! No rushing the study guide this time please guys!

PHP exe compiler & GUI apps

Tuesday, 11th July, 2006

I just read about Bambalam PHP EXE Compiler/Embedder on phpdeveloper – very cool. Then I spotted WinBinder, genius! (I wonder how performant PHP is for GUI apps)

Zend PHP 5 Certification

Sunday, 18th June, 2006

I bit the bullet last week and ordered a Zend Certification Voucher. This afternoon I went to book an exam; during Pearson Vue’s registration process Zend require you to enter a Zend network username (I forgot I had one). While scouring the site for my username I stumbled across this thread on their forums.

With the new PHP 5 certification going live in just 5½ weeks (26th July) I figure I’ll hold off booking my exam until this materialises. Now to Ebay my Zend Certification Study Guide!

You are currently browsing greg's weblog – the more I learn, the less I know archives in the PHP category.

Categories

xhtml 1.1 compliant   xhtml 1.1 compliant