utils icon indicating copy to clipboard operation
utils copied to clipboard

Deprecation warning on DateTime::createFromFormat with PHP 8.1

Open itspngu opened this issue 3 years ago • 3 comments

Version: 3.2.7

Bug Description

We use nette/caching, which uses nette/utils for date & time operations. On PHP 8.1 we get a deprecation warning when DateTime::createFromFormat is called:

NOTICE: PHP message: PHP Deprecated:  Return type of Nette\Utils\DateTime::createFromFormat($format, $time, $timezone = null) should either be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/nette/utils/src/Utils/DateTime.php on line 100

Steps To Reproduce

Create an instance of \Nette\Caching\Storages\MemcachedStorage.

Expected Behavior

I expect no deprecation warnings to show up if a package lists the used PHP version as supported.

itspngu avatar Mar 16 '22 14:03 itspngu

Update to latest version

dg avatar Mar 16 '22 16:03 dg

We are on the latest version of both packages:

$ composer why nette/utils
nette/caching  v3.1.2  requires  nette/utils (^2.4 || ^3.0)
nette/finder   v2.5.3  requires  nette/utils (^2.4 || ^3.0)

$ composer show nette/caching
name     : nette/caching
descrip. : ⏱ Nette Caching: library with easy-to-use API and many cache backends.
keywords : cache, journal, memcached, nette, sqlite
versions : * v3.1.2
[...]

$ composer show nette/utils
name     : nette/utils
descrip. : 🛠  Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
keywords : array, core, datetime, images, json, nette, paginator, password, slugify, string, unicode, utf-8, utility, validation
versions : * v3.2.7
[...]

itspngu avatar Mar 16 '22 17:03 itspngu

The fix is this line. I don't understand why it's not working for you. https://github.com/nette/utils/blob/v3.2.7/src/Utils/DateTime.php#L102

dg avatar Mar 17 '22 16:03 dg