View Issue Details

IDProjectCategoryView StatusLast Update
0027796mantisbtinstallationpublic2021-03-07 18:28
Reporterdregad Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Target Version2.25.0Fixed in Version2.25.0 
Summary0027796: Using an empty timezone causes PHP notice on PHP 8
Description

When $g_default_timezone is empty (which is the default setting in config_defaults_inc.php), on PHP 8 systems Mantis throws
SYSTEM NOTICE: 'date_default_timezone_set(): Timezone ID '' is invalid' in '/path/to/mantisbt/core.php' line 273

The default time zone is usually set by the installer and saved in config_inc.php, so this should not affect existing installations, but can easily be reproduced when installing Mantis (install.php) or by removing the $g_default_timezone option from the config file.

Everything else being equal, problem does not occur on PHP 7.4.

TagsPHP 8

Relationships

related to 0027799 closeddregad Adapt Error handler to PHP 8 

Activities

dregad

dregad

2020-12-24 05:38

developer   ~0064838

It seems that the error suppression operator is not doing its job...
https://github.com/mantisbt/mantisbt/blob/release-2.24.3/core.php#L273

After research, this is caused by the value of error_reporting being 4437 within our error handler, instead of 0 as expected [1] on PHP 8.0.0 (with PHP 7.4.13, we do get the expected value of 0). This causes it not to abort
https://github.com/mantisbt/mantisbt/blob/release-2.24.3/core/error_api.php#L144

I submitted a PHP bug: https://bugs.php.net/bug.php?id=80548. Not sure if it's an actual bug or just a documentation issue.

In the meanwhile, this may be the time to get rid of this usage of @ operator...

[1] Documentation for set_error_handler states current value of error_reporting [...] will be 0 if the statement that caused the error was prepended by the @ error-control operator.

dregad

dregad

2020-12-24 07:25

developer   ~0064841

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

dregad

dregad

2020-12-24 07:40

developer   ~0064842

So as it turns out, the change in behavior is intended, as per PHP 8.0 migration guide

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers that expect error_reporting to be 0 when @ is used, should be adjusted to use a mask check instead

I opened 0027799 to track the required adjustment to the error handler.

Related Changesets

MantisBT: master de1679d5

2020-12-23 12:57:58

dregad

Details Diff
Improve timezone setting logic

Previously, core.php tried to set the default timezone to the value
stored in global configuration, with error suppression. Due to [[1]],
this does not actually prevent the notice from appearing with PHP 8.

Refactored the code to get the system's default time zone if it is not
defined in configuration. A PHP notice is still thrown if the specified
timezone is not valid, as documented in the code.

Also, since PHP 5.4, date_default_timezone_get() no longer throws a
warning so the '@' operator is not needed anymore.

Fixes 0027796

[1]: https://bugs.php.net/bug.php?id=80548
Affected Issues
0027796
mod - core.php Diff File

MantisBT: master 328f2208

2020-12-24 10:10:21

dregad

Details Diff
Prevent system warning when creating config_inc.php

Due to the same root cause as issue 0027796, the `@` operator does not
suppress the error.

Instead of suppressing the error, check whether the parent directory is
writable before calling fopen().
Affected Issues
0027796
mod - admin/install.php Diff File