View Issue Details

IDProjectCategoryView StatusLast Update
0032840mantisbtbugtrackerpublic2023-09-03 06:08
ReporterTomekAP Assigned Todregad  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionduplicate 
Summary0032840: wrong error handling with PHP >= 8.0
Description

in error_api.php:

function error_handler( $p_type, $p_error, $p_file, $p_line ) {
    global $g_error_parameters, $g_error_handled, $g_error_proceed_url;
    global $g_error_send_page_header;

    # check if errors were disabled with @ somewhere in this call chain
    if( !( error_reporting() & $p_type ) ) {
        return;
    }

but PHP states (https://www.php.net/manual/en/language.operators.errorcontrol.php):
Warning

Prior to PHP 8.0.0, the error_reporting() called inside the custom error handler always returned 0 if the error was suppressed by the @ operator. As of PHP 8.0.0, it returns the value E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE.

so the code from PHP >= 8.0 will not return immediatelly anymore.

TagsNo tags attached.

Relationships

duplicate of 0028803 closeddregad PHP 8: "Bad Request" error on custom field filters 

Activities

dregad

dregad

2023-08-22 05:03

developer   ~0068005

Thanks for the report.

Did you actually face a situation where this caused a problem ? If so it would be good to have some details about your use case.

TomekAP

TomekAP

2023-08-22 05:18

reporter   ~0068006

  1. Extend mantis per plugin to allow filtering
  2. Go to view_all_bug_page.php, you should see this field.
  3. Click on this field to filter. You receive HTTP Error
dregad

dregad

2023-08-22 05:28

developer   ~0068007

Extend mantis per plugin to allow filtering

This is not clear, what do you mean ?

TomekAP

TomekAP

2023-08-22 07:10

reporter   ~0068008

class ....Filter extends MantisFilter {

class ....Plugin extends MantisPlugin {

public function hooks() {
    return array(
        'EVENT_FILTER_FIELDS' => 'filterFields',

public function filterFields() {
return array(
        '...Filter'
    );

Now is clearer?

dregad

dregad

2023-08-23 12:58

developer   ~0068010

Yes thank you.

Does your plugin make use of the @ operator ? Or is the offending call coming from a Mantis core function ? If so, which one(s) ?

A stack trace would help, or even better a reproducible test case so I can get a good understanding of the problem.

TomekAP

TomekAP

2023-08-23 17:22

reporter   ~0068011

Last edited: 2023-08-24 03:48

but @ has nothing here to do.
in return_dynamic_filter there is a call:

$t_content = @call_user_func_array( 'filter_form_get_input', array( $t_filter, $filter_target, true ) );

in filter_form_api there is a function filter_form_get_input:

    if( function_exists( $t_function_name ) ) {
        ob_start();
        call_user_func_array( $t_function_name, $t_params );
        return ob_get_clean();
    } else {
        # error - no function to populate the target (e.g., print_filter_foo)
        error_parameters( $p_filter_target );
        trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );
        return false;
    }

In my case the function $t_function_name doesn`t exist, so the error is thrown - trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );.
Then it is catched by error_handler and in this function:

    # check if errors were disabled with @ somewhere in this call chain
    if( !( error_reporting() & $p_type ) ) {
        return;
    }

Before PHP 8.0 it worked, becasue error_reporting() was 0 in case of @, but since PHP 8.0, error_reporting is: E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE so the condition in if is not fullfulled and we don`t immediately exit a function, but the error is being handled furthermore.
That is a difference between PHP < 8.0 and >= 8.0

dregad

dregad

2023-08-24 04:48

developer   ~0068012

Sorry but I'm still not seeing the whole picture...

but @ has nothing here to do.
in return_dynamic_filter there is a call:

$t_content = @call_user_func_array( 'filter_form_get_input', array( $t_filter, $filter_target, true ) );

But it does... Notice the @ before the call_user_func_array() ?

Anyway more importantly, which release of MantisBT are you using ?

I would guess it's an older, unsupported version because this code was removed in June 2021 (replaced by a try/catch block) and released in 2.25.2, see 0028803. So your problem appears to be a duplicate of that.

TomekAP

TomekAP

2023-08-24 05:50

reporter   ~0068013

then sorry for bothering. We were using 2.25.0, after upgrade the error disappeared. I thought PHP 8.0 is fully tested with 2.25.0

dregad

dregad

2023-08-24 06:42

developer   ~0068014

Thanks for the feedback.

You should always upgrade to the latest hotfix for a given release, to benefit from bug and security fixes.
And of course, please make sure to test with it (or a nightly build) before reporting a bug here ;-)

Anyway, good to hear that your problem is solved.