Waddle icon indicating copy to clipboard operation
Waddle copied to clipboard

Deprecation in PHP 8.1

Open vidluther opened this issue 3 years ago • 0 comments

If you're using PHP 8.1 and you try to convert the duration into a human readable string, PHP 8.1 throws a

PHP Deprecated: Implicit conversion from float 52.233333333333334 to int loses precision in vendor/duckfusion/waddle/src/Converter.php on line 102

I found a function that does the seconds to human readable conversion quickly without throwing the Deprecated notice on Stackoverflow.. https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds#19680778

I modified it to return what your function returns though..

/**
 * This is based on the answer provided here
 * https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds#19680778
 * @param $seconds
 * @return string
 */
 public static function secondsToHuman($seconds) {
        $dtF = new \DateTime('@0');
        $dtT = new \DateTime("@$seconds");
        return $dtF->diff($dtT)->format('%H:%i:%s');
}

This works for my needs, as long as I call the new method $totalDurationInHoursMinutesSeconds = \Waddle\Converter::secondsToHuman($totalDuration);

I don't know if you're still supporting/working on this code base.. but I thought I'd send this your way. iIf you're not supporting this code base please let me know, and then I'll just make this a little helper function for the little thing I'm writing.

vidluther avatar Nov 16 '21 05:11 vidluther