Topic: PHP 8.4 trigger_error($msg, E_USER_ERROR) obsolete

I guess calling trigger_error($msg, E_USER_ERROR) is obsoleted in 8.4....

My quick fix was to modify:

includes\errors.inc

- add line 26 : 
$bt = ($errno == E_USER_ERROR or $errno ==  E_USER_WARNING) ? "" : $bt;

- replace line 96: 
error_handler($exception->getCode(), sprintf(_("Unhandled exception [%s]: %s."), $exception->getCode(), $exception->getMessage()), $exception->getFile(), $exception->getLine());
_________________

modify includes\ui\ui_msgs.inc

- replace line 14:
error_handler(E_USER_ERROR, $msg, "","");

- replace line 19:
error_handler(E_USER_NOTICE, $msg, "","");

Re: PHP 8.4 trigger_error($msg, E_USER_ERROR) obsolete

Hi, thanks for this.
I have detected the same problem in 8.4 when working in an nginx container with php 8.4.5. I will just contact @itronics to see if he like this idea.

Joe

Re: PHP 8.4 trigger_error($msg, E_USER_ERROR) obsolete

is E_USER_NOTICE available in older PHP versions say 5.x ?
Any best practice for safe degradation?

Re: PHP 8.4 trigger_error($msg, E_USER_ERROR) obsolete

It looks like E_USER_ERROR is valid for trigger_error() up until 8.4.0

This from https://www.php.net/manual/en/errorfunc.constants.php#constant.e-user-error


E_USER_ERROR (int)

User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). Value of the constant: 256

Warning
Usage of this constant with trigger_error() is deprecated as of PHP 8.4.0. It is recommended to either throw an Exception or call exit() instead.

Re: PHP 8.4 trigger_error($msg, E_USER_ERROR) obsolete

Looks like the extensions too must have the function trigger_error replaced by fa_trigger_error too.

osc_orders/osCommerce.php

    $result = mysqli_query($osc, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($osc), E_USER_ERROR);

api24/sales.inc

    if ($can_process['passed'] == false) {
        trigger_error(var_export($can_process, true));
        api_error(412, $can_process['message']);
        return;
    }

The commit at: https://github.com/FrontAccountingERP/FA/commit/7092ac6864fd902b61d2c01ba694c4b5dba703fb
solves this issue for the core.

Additionally, the original function trigger_error() could have been retained for those using older extensions with older PHP versions and code.