Issue Details (XML | Word | Printable)

Key: MDL-12133
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Petr Skoda
Reporter: Petr Skoda
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

problems with changed number of parameters of validate($date, $files)

Created: 13/Nov/07 01:55 AM   Updated: 24/Nov/07 06:24 AM
Return to search
Component/s: Forms Library
Affects Version/s: 1.9
Fix Version/s: 1.9

Participants: Petr Skoda and Tim Hunt
Security Level: None
Resolved date: 24/Nov/07
Affected Branches: MOODLE_19_STABLE
Fixed Branches: MOODLE_19_STABLE


 Description  « Hide
Tim reported some weirdness related to new parameter files in mform->validate(),

I can not reproduce it on my PHP 5.2, the is_validated is calling the validate() with two parameters now, maybe the problem is in method overriding

Tim could you please test following code snippet on your server that shows those errors/warnings:
<?php
require ('config.php');

class a {
    function go($c, $d) {
        echo "a: $c $d <br />";
    }
}

class b {
    function go($c) {
        echo "b: $c <br />";
    }
}

$a = new a();
$a->go(1, 2);

$b = new b();
$b->go(1, 2);

die;



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Petr Skoda added a comment - 13/Nov/07 01:56 AM
Adding Tim...

Tim Hunt added a comment - 13/Nov/07 06:32 AM
The problem is this: Start with this code:

class a {
function go($c) { echo "a: $c<br />"; }
}

class b extends a {
function go($c) { psrent::go($c); echo "b: $c <br />"; }
}

Then change it to be:

class a {
function go($c, $d) { echo "a: $c $d <br />"; }
}

but don't chage class b. Then you get errors/notices (missing second parameter) when you call b::go and it tries to call a::go.

That is basically what you did when you changed the signature of the validate method in the base class moodleform, but not in any of the other methods that override it.

By the way, following good object oriented design, every subclass of moodleform should start with

$errors = parent::validate($data);

instead of

$errors = array();

That way, if we ever want a global validation hook we have got one. However, only the question type classes (and one or two others if I remember the results of my search) actually do this.


Petr Skoda added a comment - 13/Nov/07 03:14 PM
The call to parent is a bit problematic because we expected mixed result true/array of errors. I think we did not call parent::validate() in main moodle codebase, so there should be no warnings.

I agree this was not a nice hack, unfortunately I did not find better solution yet. I will go through all of them and fix it. Working on this today...


Tim Hunt added a comment - 20/Nov/07 08:42 PM
I have just checked in a fix for all calls to parent::validation from the question type editing forms. I hope this is a step in the right direction.

tjhunt committed 8 files to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 20/Nov/07 09:40 PM
MDL-12133 - Errors calling parent::validation in a moodle form subclass because the base class method signature was changed. This patch fixes all calls to parent::validation in the question editing forms.
MODIFY question/type/numerical/edit_numerical_form.php   Rev. 1.11.2.1    (+2 -2 lines)
MODIFY question/type/randomsamatch/edit_randomsamatch_form.php   Rev. 1.4.2.1    (+2 -2 lines)
MODIFY question/type/missingtype/edit_missingtype_form.php   Rev. 1.4.2.1    (+2 -2 lines)
MODIFY question/type/multianswer/edit_multianswer_form.php   Rev. 1.7.2.1    (+2 -2 lines)
MODIFY question/type/shortanswer/edit_shortanswer_form.php   Rev. 1.10.2.1    (+2 -2 lines)
MODIFY question/type/multichoice/edit_multichoice_form.php   Rev. 1.12.2.1    (+2 -2 lines)
MODIFY question/type/match/edit_match_form.php   Rev. 1.8.2.2    (+2 -2 lines)
MODIFY question/type/calculated/edit_calculated_form.php   Rev. 1.19.2.1    (+2 -2 lines)
tjhunt committed 8 files to 'Moodle CVS' - 20/Nov/07 09:41 PM
MDL-12133 - Errors calling parent::validation in a moodle form subclass because the base class method signature was changed. This patch fixes all calls to parent::validation in the question editing forms. Merged from MOODLE_19_STABLE.
MODIFY question/type/randomsamatch/edit_randomsamatch_form.php   Rev. 1.5    (+2 -2 lines)
MODIFY question/type/missingtype/edit_missingtype_form.php   Rev. 1.5    (+2 -2 lines)
MODIFY question/type/calculated/edit_calculated_form.php   Rev. 1.20    (+2 -2 lines)
MODIFY question/type/multichoice/edit_multichoice_form.php   Rev. 1.13    (+2 -2 lines)
MODIFY question/type/multianswer/edit_multianswer_form.php   Rev. 1.9    (+2 -2 lines)
MODIFY question/type/match/edit_match_form.php   Rev. 1.10    (+2 -2 lines)
MODIFY question/type/shortanswer/edit_shortanswer_form.php   Rev. 1.11    (+2 -2 lines)
MODIFY question/type/numerical/edit_numerical_form.php   Rev. 1.12    (+2 -2 lines)
Tim Hunt added a comment - 20/Nov/07 11:49 PM
And I have also just checked in a change so that the base class method returns array() instead of true, so you can start your overridden method with

$errors = parent::validation($data, $files);


tjhunt committed 1 file to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 21/Nov/07 12:07 AM
MDL-12133 - Errors calling parent::validation in a moodle form subclass because the base class method returns true not an empty array. This patch allow subclasses to start their validate method with

$errors = parent::validation($data, $files);

which is what you naturally want to do if you are used to object oriented programming.
MODIFY lib/formslib.php   Rev. 1.129.2.4    (+5 -4 lines)
tjhunt committed 1 file to 'Moodle CVS' - 21/Nov/07 12:08 AM
MDL-12133 - Errors calling parent::validation in a moodle form subclass because the base class method returns true not an empty array. This patch allow subclasses to start their validate method with

$errors = parent::validation($data, $files);

which is what you naturally want to do if you are used to object oriented programming.

Merged from MOODLE_19_STABLE.
MODIFY lib/formslib.php   Rev. 1.134    (+5 -4 lines)
Petr Skoda added a comment - 24/Nov/07 06:17 AM
fix in cvs, thanks for cooperation

Petr Skoda made changes - 24/Nov/07 06:17 AM
Field Original Value New Value
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Petr Skoda added a comment - 24/Nov/07 06:24 AM
Docs in wiki updated too

Petr Skoda committed 44 files to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 24/Nov/07 07:12 AM
MDL-12133 validate() method tidying up
MODIFY course/edit_form.php   Rev. 1.37.2.2    (+4 -8 lines)
MODIFY admin/uploaduser_form.php   Rev. 1.4.2.5    (+4 -8 lines)
MODIFY grade/edit/scale/edit_form.php   Rev. 1.10.2.1    (+4 -8 lines)
MODIFY grade/edit/tree/outcomeitem_form.php   Rev. 1.12.2.4    (+4 -8 lines)
MODIFY mod/quiz/mod_form.php   Rev. 1.28.2.3    (+3 -6 lines)
MODIFY login/signup_form.php   Rev. 1.35.2.1    (+5 -8 lines)
MODIFY question/type/shortanswer/edit_shortanswer_form.php   Rev. 1.10.2.2    (+1 -1 lines)
MODIFY course/moodleform_mod.php   Rev. 1.18.2.2    (+3 -6 lines)
MODIFY question/type/numerical/edit_numerical_form.php   Rev. 1.11.2.3    (+1 -1 lines)
MODIFY user/profile/definelib.php   Rev. 1.7.2.2    (+7 -12 lines)
MODIFY login/forgot_password_form.php   Rev. 1.7.2.1    (+4 -8 lines)
MODIFY course/request_form.php   Rev. 1.11.2.1    (+4 -8 lines)
MODIFY mod/forum/post_form.php   Rev. 1.21.2.2    (+5 -5 lines)
MODIFY question/contextmove_form.php   Rev. 1.2.2.2    (+2 -2 lines)
MODIFY mod/choice/mod_form.php   Rev. 1.18.2.3    (+3 -11 lines)
MODIFY enrol/authorize/enrol_form.php   Rev. 1.16.2.2    (+4 -5 lines)
MODIFY course/import/activities/import_form.php   Rev. 1.5.2.1    (+4 -4 lines)
MODIFY user/profile/index_field_form.php   Rev. 1.4.4.1    (+2 -2 lines)
MODIFY question/type/calculated/edit_calculated_form.php   Rev. 1.19.2.2    (+1 -1 lines)
MODIFY grade/edit/outcome/edit_form.php   Rev. 1.5.2.1    (+4 -8 lines)
MODIFY question/type/datasetdependent/Attic/datasetdefinitions_form.php   Rev. 1.7.2.1    (+2 -2 lines)
MODIFY grade/edit/tree/calculation_form.php   Rev. 1.7.2.1    (+4 -8 lines)
MODIFY login/change_password_form.php   Rev. 1.11.2.1    (+4 -4 lines)
MODIFY question/type/multichoice/edit_multichoice_form.php   Rev. 1.12.2.2    (+1 -1 lines)
MODIFY question/contextmoveq_form.php   Rev. 1.2.2.2    (+2 -2 lines)
MODIFY user/profile/index_category_form.php   Rev. 1.3.4.1    (+5 -9 lines)
MODIFY user/profile/lib.php   Rev. 1.23.2.1    (+3 -3 lines)
MODIFY question/type/multianswer/edit_multianswer_form.php   Rev. 1.7.2.2    (+1 -1 lines)
MODIFY grade/import/xml/grade_import_form.php   Rev. 1.5.2.1    (+3 -7 lines)
MODIFY question/type/missingtype/edit_missingtype_form.php   Rev. 1.4.2.2    (+1 -1 lines)
MODIFY grade/edit/tree/item_form.php   Rev. 1.20.2.9    (+4 -8 lines)
MODIFY user/edit_form.php   Rev. 1.24.2.1    (+9 -12 lines)
MODIFY mod/scorm/mod_form.php   Rev. 1.11.2.1    (+3 -10 lines)
MODIFY mod/glossary/edit_form.php   Rev. 1.7.2.1    (+3 -3 lines)
MODIFY grade/report/grader/preferences_form.php   Rev. 1.40.2.2    (+3 -8 lines)
MODIFY group/autogroup_form.php   Rev. 1.1.2.2    (+2 -2 lines)
MODIFY question/type/randomsamatch/edit_randomsamatch_form.php   Rev. 1.4.2.2    (+1 -1 lines)
MODIFY group/grouping_form.php   Rev. 1.1.2.2    (+4 -8 lines)
MODIFY lib/formslib.php   Rev. 1.129.2.5    (+13 -12 lines)
MODIFY question/type/match/edit_match_form.php   Rev. 1.8.2.3    (+1 -1 lines)
MODIFY question/type/datasetdependent/Attic/datasetitems_form.php   Rev. 1.9.2.1    (+1 -1 lines)
MODIFY group/group_form.php   Rev. 1.3.2.2    (+4 -8 lines)
MODIFY user/profile/field/menu/define.class.php   Rev. 1.3.2.1    (+2 -2 lines)
MODIFY mod/lesson/mod_form.php   Rev. 1.20.2.1    (+5 -12 lines)
Petr Skoda committed 44 files to 'Moodle CVS' - 24/Nov/07 07:15 AM
MDL-12133 validate() method tidying up; merged from MOODLE_19_STABLE
MODIFY grade/edit/tree/item_form.php   Rev. 1.29    (+4 -8 lines)
MODIFY grade/edit/scale/edit_form.php   Rev. 1.11    (+4 -8 lines)
MODIFY login/signup_form.php   Rev. 1.36    (+5 -8 lines)
MODIFY question/contextmoveq_form.php   Rev. 1.3    (+2 -2 lines)
MODIFY question/type/datasetdependent/Attic/datasetdefinitions_form.php   Rev. 1.8    (+2 -2 lines)
MODIFY question/type/calculated/edit_calculated_form.php   Rev. 1.21    (+1 -1 lines)
MODIFY question/type/missingtype/edit_missingtype_form.php   Rev. 1.6    (+1 -1 lines)
MODIFY user/profile/index_field_form.php   Rev. 1.5    (+2 -2 lines)
MODIFY question/type/numerical/edit_numerical_form.php   Rev. 1.14    (+1 -1 lines)
MODIFY group/grouping_form.php   Rev. 1.3    (+4 -8 lines)
MODIFY mod/forum/post_form.php   Rev. 1.23    (+5 -5 lines)
MODIFY course/import/activities/import_form.php   Rev. 1.6    (+4 -4 lines)
MODIFY question/contextmove_form.php   Rev. 1.3    (+2 -2 lines)
MODIFY course/moodleform_mod.php   Rev. 1.20    (+3 -6 lines)
MODIFY course/request_form.php   Rev. 1.12    (+4 -8 lines)
MODIFY mod/lesson/mod_form.php   Rev. 1.21    (+5 -12 lines)
MODIFY mod/choice/mod_form.php   Rev. 1.21    (+3 -11 lines)
MODIFY user/profile/lib.php   Rev. 1.24    (+3 -3 lines)
MODIFY grade/import/xml/grade_import_form.php   Rev. 1.6    (+3 -7 lines)
MODIFY question/type/multianswer/edit_multianswer_form.php   Rev. 1.10    (+2 -11 lines)
MODIFY question/type/datasetdependent/Attic/datasetitems_form.php   Rev. 1.10    (+1 -1 lines)
MODIFY user/edit_form.php   Rev. 1.25    (+9 -12 lines)
MODIFY enrol/authorize/enrol_form.php   Rev. 2.4    (+4 -5 lines)
MODIFY course/edit_form.php   Rev. 1.39    (+4 -8 lines)
MODIFY admin/uploaduser_form.php   Rev. 1.9    (+4 -8 lines)
MODIFY lib/formslib.php   Rev. 1.135    (+13 -12 lines)
MODIFY question/type/match/edit_match_form.php   Rev. 1.11    (+1 -1 lines)
MODIFY group/group_form.php   Rev. 1.5    (+4 -8 lines)
MODIFY question/type/multichoice/edit_multichoice_form.php   Rev. 1.14    (+1 -1 lines)
MODIFY grade/edit/tree/outcomeitem_form.php   Rev. 1.15    (+4 -8 lines)
MODIFY user/profile/field/menu/define.class.php   Rev. 1.4    (+2 -2 lines)
MODIFY mod/quiz/mod_form.php   Rev. 1.30    (+3 -6 lines)
MODIFY mod/scorm/mod_form.php   Rev. 1.12    (+3 -10 lines)
MODIFY group/autogroup_form.php   Rev. 1.3    (+2 -2 lines)
MODIFY grade/report/grader/preferences_form.php   Rev. 1.42    (+3 -8 lines)
MODIFY login/forgot_password_form.php   Rev. 1.8    (+4 -8 lines)
MODIFY question/type/shortanswer/edit_shortanswer_form.php   Rev. 1.12    (+1 -1 lines)
MODIFY grade/edit/tree/calculation_form.php   Rev. 1.8    (+4 -8 lines)
MODIFY question/type/randomsamatch/edit_randomsamatch_form.php   Rev. 1.6    (+1 -1 lines)
MODIFY grade/edit/outcome/edit_form.php   Rev. 1.6    (+4 -8 lines)
MODIFY user/profile/index_category_form.php   Rev. 1.4    (+5 -9 lines)
MODIFY user/profile/definelib.php   Rev. 1.9    (+7 -12 lines)
MODIFY mod/glossary/edit_form.php   Rev. 1.8    (+3 -3 lines)
MODIFY login/change_password_form.php   Rev. 1.12    (+4 -4 lines)
Petr Skoda committed 1 file to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 05/Dec/07 08:52 AM
MDL-12133 fixed regression in user advanced edit, sorry
MODIFY user/editadvanced_form.php   Rev. 1.14.2.1    (+3 -3 lines)
Petr Skoda committed 1 file to 'Moodle CVS' - 05/Dec/07 08:53 AM
MDL-12133 fixed regression in user advanced edit, sorry; merged from MOODLE_19_STABLE
MODIFY user/editadvanced_form.php   Rev. 1.15    (+3 -3 lines)