PHP Fatal error: Declaration of Cake\Chronos\Traits\FactoryTrait::createFromTimestamp

On a Ubuntu 18 package install instance, running PHP version 8.4.5, I just noticed today that emails weren’t sending and the cron.error.log shows:

PHP Fatal error: Declaration of Cake\Chronos\Traits\FactoryTrait::createFromTimestamp(int $timestamp, $tz = null): Cake\Chronos\ChronosInterface must be compatible with DateTimeImmutable::createFromTimestamp(int|float $timestamp): static in /usr/share/php/passbolt/vendor/cakephp/chronos/src/Traits/FactoryTrait.php on line 339

$timestamp is declared as an integer:

    /**
     * Create a ChronosInterface instance from a timestamp
     *
     * @param int $timestamp The timestamp to create an instance from.
     * @param \DateTimeZone|string|null $tz The DateTimeZone object or timezone name the new instance s>
     * @return static
     */
    public static function createFromTimestamp(int $timestamp, $tz = null): ChronosInterface
    {
        $instance = static::now($tz)->setTimestamp($timestamp);
        if (get_class($instance) === ChronosDate::class) {
            trigger_error(
                '2.5 Creating Date instances with createFromTimestamp() will be removed in 3.0',
                E_USER_DEPRECATED
            );
        }

        return $instance;
    }

But here is set to float:

https://github.com/passbolt/cakephp/blob/e6d338cffde833f9ea7739d7240f1a1ad93ca421/src/I18n/functions.php#L258

Changing the source code on createFromTimestamp() to mixed or int|float type permits functioning again, but it’s a change in the source code. Any thoughts on the conflict?

1 Like

Hey @garrett long time no see!

Thanks for the report, yes php 8.4 is not yet fully supported, it is going there :slight_smile:

I will create a ticket for the backend team to fix it.

Thanks!

Hi @garrett ,

thank you for the hint. PHP 8.4 is not supported on Passbolt v4.x, but will be in the coming v5.

We have a release candidate for the v5 available. See our post here.

Feel free to give it a try, and let us know if this fixed your issue!

Cheers,
Juan

1 Like

There are earlier php versions running as well. I believe the version was from what I found noted in version.php. How does the php cli version get set for the package? Whatever is the highest on update?

Edit: it was not version.php but the healthcheck. Could I add the php version binary into the cron command to bring it back down? Or is there a better way?

@max Thanks good to see you!

Glad to see you again :slight_smile: !

1 Like

Adding the last line to the /etc/cron.d/passbolt-ce-server seems to calm it down while leaving the source code as-is:

PATH=/bin:/usr/local/bin:/usr/bin
PASSBOLT_BASE_DIR=/usr/share/php/passbolt
PASSBOLT_LOG_DIR=/var/log/passbolt
PHP=/usr/bin/php8.3 <---

As a reference for others, this was based on comments found in the /bin/cake file:

# If your CLI PHP is somewhere that this doesn't find, you can define a PHP environment
# variable with the correct path in it.
if [ -z "$PHP" ]
then
    PHP=$(findCliPhp)
fi