uuid icon indicating copy to clipboard operation
uuid copied to clipboard

Return type of Ramsey\Uuid\Uuid::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize()

Open pardeep26k opened this issue 2 years ago • 3 comments

Deprecation Issue in PHP8.1

Description

Deprecated: Return type of Ramsey\Uuid\Uuid::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /wayfair/data/www/composer-packages/ramsey/uuid/src/Uuid.php on line 216 PHP Deprecated: PHPUnit\Runner\DefaultTestResultCache implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /wayfair/data/www/composer-packages/phpunit/phpunit/src/Runner/DefaultTestResultCache.php on line 34

Screenshots or output

Uploading Screenshot 2022-08-25 at 12.30.54.png…

Environment details

  • version of this package: 3.9.6
  • PHP version: 8.1
  • OS: e.g. Windows 10, Linux (Ubuntu 18.04.1), macOS Catalina (10.15.3)

Additional context

pardeep26k avatar Aug 25 '22 10:08 pardeep26k

This is the same issue as #399 and requires a change to the interface, which I can’t do in minor- or patch-level releases when following semver.

ramsey avatar Aug 25 '22 21:08 ramsey

So what is the approach then?

For now I created a file in my repository and used it instead, tests pass, but better could be new major version

<?php

namespace Radzi/Cicinas;

use Ramsey\Uuid\UuidInterface;

interface FixedUuidInterface extends UuidInterface {
    public function __serialize(): array;
    public function __unserialize(array $data): void;
}

Saltibarsciai avatar Aug 25 '22 22:08 Saltibarsciai

That sounds like a good approach. I’m working on version 5 that will solve this problem, since I can do BC breaks then.

ramsey avatar Aug 25 '22 22:08 ramsey

#[\ReturnTypeWillChange]

@ramsey can't you add this for now to surpass the deprecation warning in minor version? > #[\ReturnTypeWillChange]

pardeep26k avatar Oct 04 '22 07:10 pardeep26k

Yep. Looks like we can add the mixed return type now that the lowest version is PHP 8. Would you like to submit a PR for this?

ramsey avatar Oct 04 '22 14:10 ramsey

jsonSerialize returns :string now and so there's no problem at 4.x. You wish to release 3.9.x with a fix ?

vasilvestre avatar Oct 07 '22 13:10 vasilvestre

3.9.x still supports PHP 5.4 and 7.x. What change could we make to jsonSerialize() in 3.9.x that would support all those versions?

ramsey avatar Oct 07 '22 22:10 ramsey

@ramsey is there any timeline for a v5 release?

NeilMasters avatar Oct 25 '22 15:10 NeilMasters

This bug is fixed in version 3.9.7.

ramsey avatar Dec 19 '22 23:12 ramsey

Legend. Cheers.

NeilMasters avatar Jan 16 '23 19:01 NeilMasters

I have error:

Return type of BN\BN::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

DevelopByte avatar Nov 27 '23 21:11 DevelopByte