View Issue Details

IDProjectCategoryView StatusLast Update
0033058mantisbtplug-inspublic2023-10-31 16:32
Reporterdregad Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.23.0 
Target Version2.26.0Fixed in Version2.26.0 
Summary0033058: Unknown named parameter $files
Description

On PHP 8.0 and later, when a plugin hooks EVENT_BUGNOTE_ADD and the registered callback function does not specify the $files parameter with this exact name, Mantis throws

INTERNAL APPLICATION ERROR
Unknown named parameter $files

Steps To Reproduce

Install the following UnknownNamedParamPlugin test plugin:

<?php
class UnknownNamedParamPlugin extends MantisPlugin
{
    public function register() {
        $this->name = 'TEST Unknown Named Param';
        $this->version = '1.0';
        $this->requires = array( "MantisCore" => "2.23.0" );
    }

    public function hooks() {
        return [
            'EVENT_BUGNOTE_ADD' => 'add_note',
        ];
    }

    public function add_note( $p_issue_id, $p_note_id ) {
    }
}

Add a bug note

Additional Information

Initially reported by @vboctor on Gitter [1]

Sat, Oct 21, 2023, 03:24:05 - vboctor (Victor Boctor): dregad: fyi -- if an event trigger like this:

event_signal( 'EVENT_BUGNOTE_ADD', array( $this->issue->id, $t_note_id, 'files' => $t_file_infos ) );

the receiving function must have a parameter called $files to receive the 'files' param, otherwise a warning in through in PHP 8.

https://stackoverflow.com/questions/71241075/php-8-unknown-named-parameter-dannyvankooten-router
Sat, Oct 21, 2023, 03:26:47 - vboctor (Victor Boctor): it probably works fine when strict mode error handler for MantisBT is not on.
Sat, Oct 21, 2023, 03:39:10 - vboctor (Victor Boctor): And with named parameter support in PHP, I think the $p_ prefix for param name is going to awkward.
Sat, Oct 21, 2023, 13:41:55 - dregad: Is that an actual bug you faced?
Sat, Oct 21, 2023, 18:35:20 - vboctor (Victor Boctor): Yes. I was getting a warning when mantis settings is set to halt.
Sat, Oct 21, 2023, 18:36:43 - vboctor (Victor Boctor): But in my case the files argument wasn’t used anyways, so I believe it worked fine. The event handler had the first two arguments only.

TagsPHP 8

Activities

dregad

dregad

2023-10-29 05:02

developer   ~0068269

Bug introduced by commit MantisBT master 491f8ea9

dregad

dregad

2023-10-29 10:35

developer   ~0068272

PR https://github.com/mantisbt/mantisbt/pull/1933

Related Changesets

MantisBT: master 491f8ea9

2019-08-04 12:56

vboctor


Details Diff
Add files info to EVENT_BUGNOTE_ADD event

Added a `files` argument with array of events. Each containing id, name, and size.
Affected Issues
0033058
mod - core/bugnote_api.php Diff File
mod - core/commands/IssueNoteAddCommand.php Diff File
mod - core/file_api.php Diff File
mod - docbook/Developers_Guide/en-US/Events_Reference_Bug.xml Diff File

MantisBT: master 5e40bc3a

2023-10-29 06:30

dregad


Details Diff
Fix Unknown named parameter $files error on PHP 8+

- Remove the array key when calling event_signal() in bugnote_add() and
IssueNoteAddCommand::process().
- Update documentation

Fixes 0033058
Affected Issues
0033058
mod - core/bugnote_api.php Diff File
mod - core/commands/IssueNoteAddCommand.php Diff File
mod - docbook/Developers_Guide/en-US/Events_Reference_Bug.xml Diff File