So, Petr implemented this, Yay! (MDL-39854)
The problem now is what to do when you want to upgrade your code to take advantage (e.g. MDL-33071) and that requires you to rename your classes to have the proper frankenstyle prefix. For example, suppose you need to rename a class from quiz_old_name extends mod_quiz_new_name. This causes two sorts of code to break:
1. References to the old class name in executable code, e.g.
quiz_old_name::SOME_CONSTANT;
or
$x = new quiz_old_name();
2. References to the old class name in function declarations.
function do_something(quiz_old_name $x) {
}
This is most serious when ther is a method in a base class that you are overriding in your subclass.
You can fix many of the backwards compatibility problems by doing
/**
* @deprecated since Moodle 2.6. Use mod_quiz_new_name instead.
*/
class quiz_old_name extends mod_quiz_new_name { }
but it does not fix all the problems caused by 2. I have been playing with the following test script, without really reaching any conclusions:
<?php
require_once(__DIR__ . '/config.php');
interface testi {
public function imethod($x);
}
class mod_test {
public function method1(mod_test $x) {
print_object('In method'); // DONOTCOMMIT
}
public function method2(test $x) {
print_object('In method'); // DONOTCOMMIT
}
}
/**
* @deprecated since Moodle 2.6
*/
class test extends mod_test
// If you uncomment the next line, you get strict standards warnings about
// method1 and method2. Otherwise you don't!
// implements testi
{
public function method1(test $x) {
parent::method1($x);
}
public function method2(mod_test $x) {
parent::method2($x);
}
public function imethod($x) {
}
}
$x = new test();
$y = new mod_test();
// This works.
$y->method1($x);
// This fails with Argument 1 passed to test::method1() must be an instance of test. instance of mod_test given
$x->method1($y);
Basically, I am wondering, what is the best way to upgrade my code to work nicely in Moodle 2.6, without breaking backwards-compatibility too much.
Note that it is very easy to search and replace quiz_old_name -> mod_quiz_new_name in any custom code, so perhaps we just need to move forwards, and annoy everyone my making them fix their custom code when they upgrade to 2.6. Having been on the other end of that sort of thing, fixing OU-specific code that was broken by Moodle HQ changes in core, I don't really want to do that.