Hi,

I've been playing around quite some while with the new exceptions in PHP5 and must say that this new feature by it self is .. well, exceptional.

However .. since internal PHP function do not make use of them, it's pretty hard to produce "exception proof" software. Because earlier or later, some internal functions will always throw an PHP warnung or error. I'm talking about run-time errors here; not fatal errors. Which brings me into the dilemma that when I wisely use exceptions to catch bad runtime behaviour, I still may get out of luck because internal functions are not aware of this. In such cases either the error won't cought or will only be caught in a later stage due the domino effect.

Simple example: take mysql_query(). If it fails in a miserable way (due to malformed SQL statement, database changes, whatever), it still only produces a warning and will return false; it's not useable from the POV of exceptions.

So, to have this area covered, I started to *duplicate* internal functions in its own namespace (static class) which , in case of errors, will throw an exception, and not only a warning (the warning is still OK, it should go to a dedicated log file anyway and not the output stream).

In practive this looks like this:

class System {
        static function mysql_query() {
                $arguments = func_get_args();
                if (false === ($retval = call_user_func_array('mysql_query', 
$arguments))) {
                        if (strlen($mysql_error = mysql_error()) > 0) {
                                $mysql_error = "; mysql_error = " . $mysql_error;
                        }
                        throw new Exception("Unable to execute MySQL 
query$mysql_error");
                }
                return $retval;
        }
}


But doing this now for every internal function call I don't want to lead my program into an unwanted state isn't very appealing.


I've had given hints not to use PHP as programming language if I want to have such a degree of "safety". Not possible for me, I'm pretty mature in PHP and can't afford learning another language just because of this issue.

I'm seeking for a "more perfect" programming model for application demanding that uncontrolled factors are limited to the max.

Has anyone played around with PHP5 and thought about such issues?

cheers,

- Markus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to