Problems with strftime after webserver (php) upgrade

Having trouble installing serendipity?
Post Reply
KHoos
Posts: 3
Joined: Sat Dec 27, 2025 12:42 pm

Problems with strftime after webserver (php) upgrade

Post by KHoos »

I'm running a dormant site (no new posts, no new comments) with s9y, but I'd like to keep it accessible because it's a bit of history I want to preserve.

Recently I upgraded the webserver and this upgraded PHP to version 8.2.29 from a 7.4 version. After the upgrade the s9y site started giving 500 internal server errors. I have upgraded the s9y code to version 2.5.0 from 2.4.0, and the site went through the upgrade process when I tried it again. But after the upgrade the internal server error is back.

The error_log has the following:

[Sat Dec 27 12:35:55.465860 2025] [php:error] [pid 4467:tid 4467] [client 2a10:3781:1669:1:e77c:ac37:ea8c:2d74:0] PHP Fatal error: Uncaught TypeError: PHP81_BC\\strftime(): Argument #1 ($format) must be of type string, null given, called in /home/httpd/netwerkgroep/html/serendipity/include/functions.inc.php on line 143 and defined in /home/httpd/netwerkgroep/html/serendipity/bundled-libs/php81_bc/strftime/src/php-8.1-strftime.php:30\nStack trace:\n#0 /home/httpd/netwerkgroep/html/serendipity/include/functions.inc.php(143): PHP81_BC\\strftime()\n#1 /home/httpd/netwerkgroep/html/serendipity/include/functions.inc.php(191): serendipity_strftime()\n#2 /home/httpd/netwerkgroep/html/serendipity/include/functions_smarty.inc.php(750): serendipity_formatTime()\n#3 /home/httpd/netwerkgroep/html/serendipity/templates_c/moz_modern/34/a5/10/34a510de078cc5834317af88c0c67b0882fe1767_0.file.entries.tpl.php(51): serendipity_smarty_formatTime()\n#4 /home/httpd/netwerkgroep/html/serendipity/bundled-libs/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_694fc439e4e3f6_31921430()\n#5 /home/httpd/netwerkgroep/html/serendipity/bundled-libs/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode()\n#6 /home/httpd/netwerkgroep/html/serendipity/bundled-libs/smarty/smarty/libs/sysplugins/smarty_internal_template.php(217): Smarty_Template_Compiled->render()\n#7 /home/httpd/netwerkgroep/html/serendipity/bundled-libs/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(238): Smarty_Internal_Template->render()\n#8 /home/httpd/netwerkgroep/html/serendipity/bundled-libs/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(116): Smarty_Internal_TemplateBase->_execute()\n#9 /home/httpd/netwerkgroep/html/serendipity/include/functions_smarty.inc.php(82): Smarty_Internal_TemplateBase->fetch()\n#10 /home/httpd/netwerkgroep/html/serendipity/include/functions_entries.inc.php(1364): serendipity_smarty_fetch()\n#11 /home/httpd/netwerkgroep/html/serendipity/include/genpage.inc.php(126): serendipity_printEntries()\n#12 /home/httpd/netwerkgroep/html/serendipity/include/functions_routing.inc.php(18): include('...')\n#13 /home/httpd/netwerkgroep/html/serendipity/index.php(104): serveIndex()\n#14 {main}\n thrown in /home/httpd/netwerkgroep/html/serendipity/bundled-libs/php81_bc/strftime/src/php-8.1-strftime.php on line 30

So somehow strftime is called 'wrong' but even resetting the template I once created to a standard template doesn't fix this. I found out can access the serendipity admin side, so it was possible to change frontend template.
Last edited by KHoos on Sat Dec 27, 2025 11:46 pm, edited 1 time in total.
KHoos
Posts: 3
Joined: Sat Dec 27, 2025 12:42 pm

Re: Problems with strftime after webserver (php) upgrade

Post by KHoos »

I dove into the traceback and I seem to have fixed this for now. In serendipity/include/functions_smarty.inc.php
change

Code: Select all

function serendipity_smarty_formatTime($timestamp, $format, $useOffset = true, $detectTimestamp = false, $useDate = false) {
    if ($detectTimestamp !== false && stristr($detectTimestamp, 'date') === false) {
        return $timestamp;
    }

    if (defined($format)) {
        return serendipity_formatTime(constant($format), $timestamp, $useOffset, $useDate);
    } else {
        return serendipity_formatTime($format, $timestamp, $useOffset, $useDate);
    }
}
to

Code: Select all

function serendipity_smarty_formatTime($timestamp, $format, $useOffset = true, $detectTimestamp = false, $useDate = false) {
    if ($detectTimestamp !== false && stristr($detectTimestamp, 'date') === false) {
        return $timestamp;
    }

    if (defined($format)) {
        return serendipity_formatTime(constant($format), $timestamp, $useOffset, $useDate);
    } else {
        return serendipity_formatTime("%a %b %d %H:%M:%S %Y", $timestamp, $useOffset, $useDate);
    }
}
the undefined value of $format needs to be handled. I chose a default format.
KHoos
Posts: 3
Joined: Sat Dec 27, 2025 12:42 pm

Re: Problems with strftime after webserver (php) upgrade

Post by KHoos »

Although this makes the posts visible again there is still functionality broken: on editing a post the date/time will be lost and the post will be invisible. So this is not the complete solution but it acts as a workaround for a dormant site.
onli
Regular
Posts: 3044
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Problems with strftime after webserver (php) upgrade

Post by onli »

This is one way to fix it, the other would be to check in moz_modern why the format is missing. It seems to originate from its entries.tpl?

But you are right, this is a bug. The code is written as if one could call serendipity_formatTime with $format set to null, but at least since the move to PHP81_BC\\strftime $fomat was not allowed to be null. I will open a github issue and hope to fix it for 2.6.

Edit: Github-issue is https://github.com/s9y/Serendipity/issues/946

Note that the post being hidden after an edit sounds strange to me. It might explain the initial issue, that there is an underlying bug of the timestamps not being accessible. Not sure how that might happen.
Post Reply