php5 - new coding standards?

php5 - new coding standards?

by Penny Leach -
Number of replies: 33
With the switch to php5 for Moodle 2.0, there are a number of new programming things we can take advantage of... it would be good for the development community to come to some sort of consensus on these...

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
Then for more specific cases, you can write subclasses (eg CourseNotFoundException might be a subclass of UserException).

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 smile 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.
Average of ratings: -
In reply to Penny Leach

Re: php5 - new coding standards?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I just like to chuck in my $00.02 here to make some cautious noises. It's very easy to use objects and exceptions to write terribly elegant code which, unfortunately, is completely unfathomable.

I've spent hours over the last couple of days trying to get the slightest grip on how formslib works with only very slight success. I'm sure it's very clever but the multiple abstractions and class 'extends' make it a feat of mental gymnastics to understand.

I believe it was always one of Moodle's advantages that it was accessible to non professional programmers and I think it would be a shame if that was lost. I appreciate that isn't what you are suggesting Penny, but I do start to worry that we are heading in that direction.

P.S. I do have a Computer Science degree by the way, but it was back when punched cards where still about. Yes I really am that old big grin
In reply to Howard Miller

Re: php5 - new coding standards?

by Dan Poltawski -
I'm afraid I just do not think the fear of action at a distance is a reason to shy away from great stuff OO brings you, especially as its equally possible with non-OO code[1] & OO could probably help improve a lot of situations.

Better to generally stick to the principle of ensuring you do not over-abstract so much that it becomes unreadable.

I agree that one of Moodles strengths is the easily accessible codebase, but equally we must ensure we don't get scared into letting this become a hindrance! Else we will live in danger of some one come along, borrowing all Moodle concepts and create Moodlezr 2.0 beta, with rounded corners, rapid development and a drag and drop interface. We'll all be stuck maintaining the hard line that we can't do nice drag and drop UI's since its too complicated and the users will switch.

Better to concentrate our efforts into getting our documentation and support material up to scratch as I believe this is the real barrier for new developers which we need to work on.

[1] (I know i've had particularly bitter experiences tracing deep inside 10/20 functions finding a non-error reporting error in the restore code, for example).
In reply to Dan Poltawski

Re: php5 - new coding standards?

by Martín Langhoff -
In large systems, even action-at-a-moderate-distance is a major problem. I am perpetually wary of inheritance, which is the main source of magic action-at-a-distance.

I am also wary of Exceptions, unfortunately. I am now coding a lot of code that has to handle every possible error condition, and exceptions are a pain to deal with - I have to walk down every damn library used and come up with a manifest of all the possible exceptions thrown. And if a library I use changes the libraries it uses internally, new exceptions might be thrown that I have no control of. Ugly long term maintenance story.

Both inheritance and exceptions look good in the small cases, but in large systems... homeopatic doses only...
In reply to Martín Langhoff

Re: php5 - new coding standards?

by Penny Leach -
Ah Martin, I was wondering if you were going to chime in.

My general approach to inheritance (where it relates to exceptions at least) is that a very well thought out inheritance tree should be defined for specific types of exceptions. What I am currently advocating is that this should be defined by behaviour (eg, what happens when that type of exception is thrown).

Exceptions that inherit from Userexception when thrown, trigger a very different handling behaviour to exceptions that inherit from Bugexception.

The reason it's important to define subclasses of these (eg, Filenotfoundexception which extends Userexception) relates to what you tell the user happened. The more specific the exception that gets thrown , the more specific you can be to the user about what happened.

The best way to do this is to throw specifically and catch generally.

Your problem of having to come up with a manifest of all possible exceptions means that there's no good inheritance tree. You shouldn't have to catch every possible exception, you should be able to catch generally (eg catch BugException vs catch BugExceptionOfType56454InLibraryFoo).

Additionally , you register a default exception handler (Moodle already has this, as TIm I think, pointed out) - all uncaught exceptions fall through to that and it does something depending on which branch of the inheritance tree it belngs to. The more specific the thrown exception, the better chance it has to tell the user something sensible about what happened (eg UserExceededQuotaDuringFileUpload rather than just Exception)

Edit: in anticipation of Petr coming along and saying that he thinks this should be handled outside inheritance, by using object properties or something else, the rationale is:

Exceptions should be able to define their own display/handle behaviour rather than the default exception handler doing it. You should be able to call $e->display() on the object that was thrown and have something sensible happen. In that case, UserException would show something nice to the user saying, your fault, sorry. BugException would show something nice to the user saying, my fault, sorry (and maybe print something to the log, and/or email a developer). SecurityException might opt to email the site administrator.

You define this behaviour in the three or four *base* exceptions, and then the reason you create new exceptions that inherit from them (see above) is so they can be thrown specifically (with their own error messages), but also so that they can override the default render behaviour if they like. Eg SecurityException in the general case might email the site administrator, but LoginFailureException which extends SecurityException wouldn't, so it would override that.
In reply to Dan Poltawski

Re: php5 - new coding standards?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Used well OO can give spectacular results and wonderul transparency. However, it is a big stick and as such it can do terrible damage. I've seen it used innapropriately many more times than appropriately.

It's simply a matter of balance - Moodle has been good at that in the past. Let's just make sure we don't have "Yay, PHP5 has all this cool stuff. How can we use it". Simplest is, nearly always, best.

As an aside, I confess that I hadn't heard the expression "action at a distance" before. It wonderfully describes the problem though smile
In reply to Penny Leach

Re: php5 - new coding standards?

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Hi!

Exceptions
yay! I like the top level exception types. The first benefit we found was that unit testing is much easer with them (error and print_error now throw exceptions when unittest environment detected). The existing exception code is not final, I just made it work somehow in a limited area of DDL library. My +1 for any refactoring there if it makes it better.

PHP5 magic __set() and __get() aka object overloading
It seemed like a nice idea especially for keeping backwards compatibility. Unfortunately it does not work as expected if you use arrays in object properties. The current session code in HEAD is broken because of this sad I am going to refactor the session code next week again, sorry. My +1 to not use this feature at all in Moodle code.


I agree the new coding style (especially OOP) will be problematic for some people, for others it will be a blessing though. It is possible to write a spaghetti code using any approach - badly designed OOP model is often worse than old style function mess. Formslib is, ehm, not perfect at all, we have tried (me and Jamie) to make it as simple to use as possible and hide a lot of the differences in quickforms internals, if you start digging deep you might uncover a lot of strange complex code wink

Petr
In reply to Petr Skoda

Re: php5 - new coding standards?

by Penny Leach -
Yay!

I agree about exceptions, perhaps Petr you and I (and any other interested parties) can have a scheduled brainstorming session about it (and I can walk you through what we've done with Mahara, or you can have a look in the source code)

__set and __get - I'm happy to not use these too. While writing the portfolio API I have been actually writing set and get methods manually and making the class vars private.

I like __destruct though. Especially as a means to detect uncommitted (to database) changes.
In reply to Penny Leach

Re: php5 - new coding standards?

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Sounds like a good plan, I should finish the proposal and code samples for File API sometime next week then we could start working on this in parallel.
In reply to Petr Skoda

Re: php5 - new coding standards?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Don't get me wrong... well done OOP can be great but, as you say, it can be used as an excuse for some incredibly over-complex coding. Anybody familiar with a lot of Java libraries will know exactly what I'm talking about smile It's knowing when it's getting in the way of the job I guess.
In reply to Petr Skoda

Re: php5 - new coding standards?

by Martín Langhoff -
We use 3rd party libraries, can we force their exceptions to inherit from ours easily? Otherwise, any moodle-centric exceptionmodel will break everytime we use 3rd party libs (that is - most of the time).
In reply to Martín Langhoff

Re: php5 - new coding standards?

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
There is a trend to wrap anything 3rd party in special Moodle layer, this keeps the API simpler, allows upgrades of 3rd party code without breaking public Moodle API and it would imho also allow us to rethrow exceptions to match Moodle conventions. Both DDL and DML already do this, I suppose portfolios and file storage will do the same.
In reply to Martín Langhoff

Re: php5 - new coding standards?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Programming without exceptions is absolutely *** **** insane unless you hold an incredibly tight rein on every single developer to ensure that every single error condition is checked at every point. Which, if you do that, is fine, but this has not typically been the case in Moodle development.

(Did you spot the understatement in my last paragraph? Look carefully! It's there. smile)

This is why (just for example) backup/restore is a continuing maintenance disaster, especially for anybody who uses or maintains custom modules. At present, if anything or everything fails in backup, the most likely outcome is that there is no error message output and the system says that backup completed succesfully. Great result! Until you try to restore it, that is.

This is all caused because some functions return false and some other functions ignore that return value. Making it work involves correctly implementing a massive tree of return checks and horrible display in all different places, each of which needs to check for BACKUP_SILENT or whatever it is and maybe suppress the message, and so on.

A lack of exceptions is also why, for example, we (OU) had a serious bug with contexts recently. The build_context_path function works using a 'temporary' (but actually permanent...) table mdl_context_temp. Before each run this is wiped using TRUNCATE mdl_context_temp. Fine right? Now for various reasons this doesn't work on our particular Postgres configuration (you need to do DELETE FROM). But, because the database functions only return error codes instead of throwing exceptions, and because obviously nobody was going to check for error codes when doing TRUNCATE because come on how on earth could that ever fail, this was happening silently and causing severe problems (we moved things to other category, context gets updated correctly to new category... then a few hours later cron updates it back again).

If we'd had exceptions, this would have thrown an exception which (presuming nothing else caught it) would just display in the cron logs, or when running cron manually. We would have spotted it before the code even went live.

Exceptions are a life-saver: if something fails you know it and can fix it. And there's absolutely no reason to identify every piddling type of exception or maintain any kind of list; if you are catching problems and checking exception types, just throw in a general catch last.

For that reason it's probably not necessary to do anything specific with third-party exceptions (some other kind of error occurred? ok let's display it, end of). However if this is necessary (it is in Java and other languages where you have the concept of 'checked exceptions' ie Java will require you to catch any exception that might possibly be thrown or else you get a compile error) then it isn't very difficult. Here's some typical java code:

try
{
xmlLibrary.doXmlStuff(f);
}
catch(XMLLibraryException e)
{
throw new MyProgramException(e);
}

This uses the concept of a 'cause'. Is that in php exceptions? They were mostly taken from java so I assume so... if not it's easy to include in any specific exception type. Basically it just means that the original exception is stored as a member variable inside your own exception type, so that when you display the backtrace, you can include the trace from the original exception as well as the place where you re-threw it.

I've actually found it quite rare that you need to catch specific exceptions for different handling (i.e. where you have a try/catch block with more than one catch, and they aren't all doing the same thing). There are only a few special cases where that is often required (e.g. treating FIleNotFoundException differently from a more general IOException, that kind of thing).

--sam
In reply to Penny Leach

Re: php5 - new coding standards?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Exceptions YES PLEASE. Those four types sound fine to me. I'm too lazy to create subclasses generally so if we can use the standard ones as-is that would be good please smile For the times when we do need subclasses, can we make displaying the exception handled by the exception itself, so that it could be overridden to control what it displays, where the Continue button goes, whether it sends an email or whatever, etc. So rather than having an exception handler with a 'which type of exception is it' if, the handler just catches MoodleException and does ->display() or whatever.

Tracking dirty objects EH MAYBE - I've done that in some parts but it doesn't seem like something that would necessarily need to be a global pattern. I wouldn't really like to see it done 'secretly' I think... I guess it would save time if people use the get_record/update_record paradigm exactly (i.e. that will try to set all sorts of fields you didn't change) but maybe we could add some instrumentation to the get_record result to make this happen without changing the way it works? (I.e. store the 'original' record as well and make update_record compare fields before putting them into the sql.)

With regard to destructor behaviour there is something similar in the OU's transaction class (transaction_wrapper)...

...Which beings me onto my wishlist item... yes, transactions. I'd like to see something like that adopted by core; ours works as follows:

$tw=new transaction_wrapper();
// code that does stuff in db
$tw->commit();
or
$tw->rollback();

You are allowed to nest transactions, although if any nested transaction fails, all of them fail (this is because Postgres at least doesn't actually support nested transactions). Each constructed object must have a commit/rollback call.

This is the bit where it's similar smile - in the destructor, if it hasn't been committed, it prints a (developer debug) trace of the line where it was created so you can tell. Obviously, if you fail to commit the transaction, you need to know because nothing is going to happen.

Transactions are a big thing Moodle is missing (here we definitely cannot live without them in a few areas, and don't see why we should live without them in others), and they don't cause any problems on databases that don't support transactions. So it would be very good (a) to support transactions properly - nesting is required for sure, begin_sql is no use - and (b) to do it using a nice approach that detects errors. (We also did convert legacy begin_sql and commit_sql etc to use transaction_wrapper but for 2.0 those could be chucked.)

--sam
In reply to sam marshall

Re: php5 - new coding standards?

by Penny Leach -
I totally agree about transactions!

As far as I know, postgres is the only one we have that supports DDL in transactions, are we even using it for database ugprades?! If not we definitely should be. Each step of the upgrade should run in a transaction. I know that it will only make a difference on 1/4 databases, but even so it's incredibly worth it.

Do PDO/ADODB support (tracking) nested transactions or is it up to the application to do it?

I think these things take a long time to implement across the board, but we should be building in support for them so that we can start as we mean to go on smile
In reply to Penny Leach

Re: php5 - new coding standards?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
MSSQL supports transactions for 'create table' etc as far as I'm aware, so it's only MySQL (?) and Oracle that don't. (Actually are people sure the latest Oracle version still doesn't? I should ask Rod here, he's supposedly been trained on it, but not sure if they covered that, it was only a week...)

That's a good point though - I think actually you would need to specify when constructing a transaction whether it is a 'DDL transaction' (in which case, don't bother trying to do it on Oracle/MySQL). Obviously could just be an =false parameter so normal transactions would be fine.

ADODB does have nested transaction support. I attached transaction_wrapper.php so you can see how it works if you want, not very complicated. (Some of the code is a bit of a mess but whatever.)

And I don't know about core moodle, but OU moodle does use transactions on updates. smile One other important part is restore - if restore breaks you end up with a half-created site, which is horrible. Don't think core moodle has a transaction there (we do).

Deleting courses would be good case for a transaction too, also creating and deleting activities (so you can't end up with course-module but no activity table entry or vice versa), etc etc.

--sam

In reply to sam marshall

Re: php5 - new coding standards?

by Dan Poltawski -
MSSQL supports transactions for 'create table' etc as far as I'm aware, so it's only MySQL (?) and Oracle that don't.

Just for info.. MySQL does support transactions with the InnoDB storage engine, which isn't of much use to moodle, which uses the MyISAM engine ;)
In reply to Dan Poltawski

Re: php5 - new coding standards?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I had understood that MySQL does not fully support transactions even when using InnoDB. (Incidentally, when I've been misguided enough to install MySQL in the past, I've always configured it to use InnoDB by default - don't know if, in those circumstances, Moodle would use it, or whether it actually forces table type to the broken version.)

By 'fully' I mean that though transactions work fine for the normal run of things (inserting, updating) I understood they don't work for commands that alter the structure of the database (create table, alter table, drop table).

Postgres and MS SQL transactions both do work for database structure changes, but I thought MySQL using InnoDB and also Oracle (I asked our trained-person here about that, he thinks it's still the case) only support transactions for what corresponds to Moodle's DML layer, not DDL. If that continues to be the case, that's why a transaction wrapper in Moodle would probably need to handle DDL changes differently in some way, such as by a flag.

Because upgrades are a key area where things might go wrong (especially when using a customised version of Moodle), transactions are pretty important there (and when/if we switch to Oracle, losing that is going to suck). But obviously it's still beneficial to have transactions during normal usage, even in cases (Oracle, MySQL) when they aren't available for upgrades.

--sam
In reply to Dan Poltawski

Re: php5 - new coding standards?

by Penny Leach -
Hi Dan smile

InnoDB does support transactions, but only for data changes, not schema changes. Mysql will happily let you do

begin;

drop table mdl_config;

# crap! I didn't mean to do that!

rollback;

but .. too late, your mdl_config table is gone.

begin;

delete from mdl_config;

rollback;


works, however. (again, only with innodb)
In reply to sam marshall

Re: php5 - new coding standards?

by Penny Leach -
Exception handling -

That's basically what we did in Mahara.

The base exception class has a render_exception function and it gets overridden in each of the four main classes (which subclass MoodleException)

Then if you want to make a more specific exception, you can subclass whatever of the four you like and override render_exception or display or whatever.

The other thing is that it's important to realise that at the point the exception is thrown, the core libraries might not have been loaded, which means functions like get_string might not be included yet. We ended up checking for the function and if it existed, fine, call it so the user gets their language, else fall back to a hard coded english string (inside the exception class).

There's not really much you can do about that. If you don't have the language libraries available, you really have to use english.

Same goes for display libraries like weblib and stuff. We were using smarty, and in the exception handler, we check to see if smarty is available, and use the error template, else fall back to some pretty boring HTML that doesn't require calling any functions that might not be loaded yet. We'd have to do the same thing for functions like print_header and such.
In reply to Penny Leach

Re: php5 - new coding standards?

by Mark Nielsen -
+1 for Exceptions

I have been playing around with them in some of my more recent code and found them to be quite useful. Probably on everyone's mind already, but would be great if the exception class would also print a debug traceback if debugging is turned on. Also, I used the error code parameter as a flag for the type of string being passed. Zero was use the string in a get_string() call and 1 was use as is. This was for a module though, so the get_string() call was always for the module, but might be handy for quickly writing generic exception errors.

Since we are talking about PHP5 coding standards, has anyone thought about using __autoload()? Might help to reduce Moodle's memory usage and would probably require a naming convention for classes like how Zend Framework names the classes based on the directory structure and the file names.
In reply to Penny Leach

Re: php5 - new coding standards?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I think I'd just do it like

MoodleException($errorcode,$module,$a=null)

then if an error occurs it does get_string('err_'.$errorcode,$module,$a) but if get_string isn't available it could just 'Error $errorcode occurred in module $module'. Link to moodledocs based on error code could still work...

I.e I wouldn't make people include an english version of the string, just display the language string name basically. After all that kind of exception should never really show to users. (Yeah, I know, it will, but not very often, and if the system is that broken, we should probably be using our separate 'apology server' - love that name - to give people a generic 'sorry it's broken' page rather than letting moodle render anything at all.)

...actually it occurs to me, even without complicated load-balancer installations and other non-Moodle stuff, maybe exceptions that do occur before setup.php is triggered should in fact always show a generic user-friendly 'we're really sorry sad' page anyway. One trick we did in old systems is to always print the real error message in an html comment smile So users get the terribly polite, helpful, totally uninformative error, while a developer can just view source and find out what's wrong straight away.

--sam
In reply to sam marshall

Re: php5 - new coding standards?

by Mark Nielsen -
Perhaps have $module default to something as well, like exceptions (for a nice set of generic error messages) or moodle. I'm hesitant about adding err_ to all the error codes as we will have to redefine all of our error strings.

but if get_string isn't available it could just 'Error $errorcode occurred in module $module'. Link to moodledocs based on error code could still work...

Great idea, the error would just be a grep away ;)
In reply to Mark Nielsen

Re: php5 - new coding standards?

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Agreed - especially you are right about not adding err_. I had forgotten the need to reuse existing strings.

And talking of defaults gives me another make-life-easier idea: there could even be a default error message string depending on the type of exception. (So if you throw a databaseexception or whatever, you just get a 'There was a database error in processing your request', which is probably sufficient for most errors where we wouldn't expect to occur.) This would still be OK for developers because of course in debug mode it would show the backtrace.

--sam


In reply to sam marshall

Re: php5 - new coding standards?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Have a look at moodle_exception in HEAD. It is already quite nice. And there is a default handler that makes throwing one basically equivalent to doing a print_error call.
In reply to Tim Hunt

Re: php5 - new coding standards?

by Brian Jorgensen -
Hey, All:


I would like to be able to throw exceptions in 1.9 and know that whatever I've stubbed in will forward port fairly easily to the 2.x line.

http://cvs.moodle.org/moodle/lib/setuplib.php?view=co

has the coding_exception, but not the other 3 that Penny was talking about (bug_exception, security_exception, and user_exception). Will these three also be added?

Alternatively, is there a doc in the wiki that I've missed?


Thanks,

Brian
In reply to Penny Leach

Re: php5 - new coding standards?

by Bryan Williams -
Mike Churchward is on vacation this week, otherwise I know he would be jumping into this discussion. He's fully torn out most of his remaining hair over formslib this past several months, and I'm sure he can share quite a bit. Perhaps Helen could set up a virtual developers meeting on the subject, and other issues raised in this thread. smile
In reply to Bryan Williams

Re: php5 - new coding standards?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think I (eventually) worked out what I needed to know about the Pear forms thingy. Let us never speak of it again big grin
In reply to Penny Leach

Re: php5 - new coding standards?

by Aaron Barnes -
I think another important thing that should be documented is when to use exceptions. Some people use them instead of returning true or false, others just use them for exceptional circumstances.

I think Moodle's expected circumstances for exception usage needs to be well defined.

My 0.2c.

Love the 4 global exception sub classes, will be using them in the future in my own projects!
In reply to Penny Leach

Re: php5 - new coding standards?

by Brian Jorgensen -
Hey, Penny:


I'm writing a moodle admin report to display the installdate and builddate of certain rpms on our servers; my rpm class is throwing exceptions when the supplied querytags are not supported (a local subclass of UserException); when the requested package is not actually installed (same); and when the rpm command returns more than one line for me to parse (??).

It's the last case that I'd like your opinion on. Currently, this is my "canary" exception for "at this time I only expect one line to be returned."

Though this will help show weaknesses in my assumptions about what the rpm command may return to me, it will also protect me if what the command returns (basically the "API") changes for parts that I believe I understand.

Rather than thinking of these as CodeExceptions, I would really rather treat these as "external" exceptions... maybe a PackageManagerException subclass of a ServerException? Which, to me, then makes this PackageManagerException feel like a "peer" of the DatabaseException.

So by your way of thinking, could DatabaseException be a subclass of a more generic ServerException for when php code interacts with other systems on the server?

Or how do you (and the community) think about cases like this?


Thanks,

Brian
In reply to Brian Jorgensen

Re: php5 - new coding standards?

by Penny Leach -
Hmm. Tricky question.

I don't think Petr and I actually resolved the differences in beliefs about exception handling.

I'm not sure I think of this as a peer of database exception because it's more specific. It's definitely a child *of* a peer though.

Actually we seem to have ddl_exception and dml_exception rather than database_exception.

I would be tempted to do something like

class shell_exception extends moodle_exception {}

class rpm_exception extends shell_exception {}


'shell_exception' isn't really the nicest way of calling it though as it's kind of linux specific.... I can't think of a better name right now though and it's dinner time!

hope that helps!
Penny
In reply to Penny Leach

Re: php5 - new coding standards?

by Thomas Bristol -
php5 is not using xslt library anymore. Will Moodle 2.0 stop using it to migrate a course from Blackboard to Moodle?
In reply to Thomas Bristol

Re: php5 - new coding standards?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Hi Thomas,

I'm guessing you are referring to the WEBCT import script that Dan Stowell wrote a while ago and is available here:
http://moodle.org/mod/data/view.php?d=13&rid=94

This script is not a core module - it is a 3rd party script and you have to download it separately. A range of people have hacked on it over the time since Dan wrote it to make it work with newer versions.

I'm not aware of any plans at this stage to convert the script to work in Moodle 2.0 or for removing the dependency on XSLT - It will likely be a good chunk of work to do this, and may not happen for a while after 2.0 has been released. - In the meantime it would likely be more cost-effective for institutions to set up a 1.9 test site to convert their webct courses, then take a backup of the course within their Moodle 1.9 test site, then take that Moodle 1.9 backup into their Moodle 2.0 site to restore.

If you would like to help fund this work you could contact your local Moodle Partner, or if you have developers that could do the work, you could share your code in the forums.