$ params的php语法错误[关闭]

This is probably a simple question, but I don't even know what search terms to use to find an answer.

I'm trying to update an existing php plug-in in a Learning Management System (Moodle). The code for one part of the plug-in is essentially just a copy of some code from the core code.

Plug in code:

$grade = $assign->get_user_grade($params['userid'], false);

which mostly copies core Moodle code:

$grade = $this->get_user_grade($userid, false, $attemptnumber);

The plug-in is missing the "attemptnumber" parameter, and I want to include it. When I change the code to:

$grade = $assign->get_user_grade($params['userid'], false, ['attemptnumber']);

my code editor says I have a syntax error. What's wrong with it, and how do I fix it?

It probably should be:

$grade = $assign->get_user_grade($params['userid'], false, $params['attemptnumber']);
                                                           ^ (here added $params)

The function expects the 3rd parameter to be an integer

/**
 * This will retrieve a grade object from the db, optionally creating it if required.
 *
 * @param int $userid The user we are grading
 * @param bool $create If true the grade will be created if it does not exist
 * @param int $attemptnumber The attempt number to retrieve the grade for. -1 means the latest submission.
 * @return stdClass The grade record
 */
public function get_user_grade($userid, $create, $attemptnumber=-1) {

So as already answered above, it should either be $attemptnumber of $params['attemptnumber']