01495: datefmt_create returns null

Summary: datefmt_create returns null
Created: 2023-10-01 19:14
Status: Closed - fixed for 2.3.27
Category: Bug
Assigned:
Priority: 3
Version: 2.3.26
OS: Apache2 / PHP 8.2.7

Description: pmwiki.php line 765 contains the following code:

return datefmt_create(@$locale, $ifmt[0], $ifmt[1], $tz, null, @$ifmt[2])->format($timestamp);

On my system, datefmt_create(...) is null, therefore null->format() will fail.

I do not know why this happens.

As workaround I did the following, but I understand that this is not a proper fix:

$tmp = datefmt_create(@$locale, $ifmt[0], $ifmt[1], $tz, null, @$ifmt[2]); if ($tmp) return $tmp->format($timestamp);

Daniel Marschall?

Update:

The parameters passed to datefmt_create() are the following:

Param 1: NULL [$locale is not existing, therefore @$locale is NULL]

Param 2: 0

Param 3: 0

Param 4: europe/berlin

Param 5: null

Param 6: MMMM

The backtrace :

  1. 1 [internal function]: PPRC->ftime(Array)
  2. 2 /daten/homes/.../public_html/wiki/pmwiki.php(740): preg_replace_callback('...', Array, '...')
  3. 3 /daten/homes/.../public_html/wiki/pmwiki.php(431): PSFT('...', 1696188191)

Daniel Marschall?

The timezone should probably be "Europe/Berlin" with initial capital letters, not all lowercase. Can you please try this and report? I agree this should be handled more gracefully. --Petko

Thank you, this was the solution!

In my php.ini I changed

date.timezone = europe/berlin

to

date.timezone = Europe/Berlin

Yes, it would be great if the handling could be changed in the future, maybe even allow a fall-back timezone in case a totally invalid value is in the php.ini file.

We may not know if the problem is with the timezone, or the format, or something else, moreover we wouldn't want to force a different timezone from the one expected. So for PmWiki 2.3.27, if datefmt_create() returns null or false, just the format like "%B" will be returned. --Petko