The main thing that I care about at the moment is Exceptions. I know that Petr has implemented them in the new dml libraries, but I wonder what the general policy is for the rest of the code.
As far as I see it, the best way to deal with exceptions in Moodle is to create a hierarchy of Exception classes for different scenarios. This might be something like:
Top level exception types:
- UserException - for whenever the user does something daft
- SecurityException - for things like missing or invalid sesskey, etc
- DatabaseException - anything to do with database
- CodeException - for unexpected things happening internally
And then we can slowly convert calling code to try {} catch {}, but to start off with (and actually probably keep), we can register different ways of dealing with the different top levels, in the uncaught case.
For example, when the default error handler catches a UserException, it can display a nicer message to the user. CodeException could email the site administrator.
Of course, this is pretty much what we did for Mahara and it's working quite well, and I think it's quite an elegant solution.
The other thing I'm thinking of at the moment, is with objects that have set methods (or __set although I'm not going there yet), we can do a trick in __destruct to detect uncommitted changes.
Workflow goes something like:
$object->set() internally sets a private class variable called $dirty to true.
$object->commit() doesn't need to write to the database if $dirty is false. if it does write, $dirty gets set back to false.
__destruct() method can detect $dirty being true and complain (eg throw a CodeException, which might be hidden from the user but emailed to the administrator)
Actually I'm not sure of this last one... exceptions thrown in __destruct might not be able to be caught by the registered exception handler. I would need to check.
Anyway what are people's thoughts about this? My feeling is that we should leverage as much as we can of the advantages of php5 as early as we can so that people can get into the habits of using them far before Moodle 2.0 is actually released.