Skip to content

FunctionNameRestrictions/NewMagicMethods: special case the magic __[un]serialize() methods#1331

Merged
wimg merged 1 commit intodevelopfrom
feature/newmagicmethods-dont-throw-warning-for-serializable-with-magic
Apr 14, 2022
Merged

FunctionNameRestrictions/NewMagicMethods: special case the magic __[un]serialize() methods#1331
wimg merged 1 commit intodevelopfrom
feature/newmagicmethods-dont-throw-warning-for-serializable-with-magic

Conversation

@jrfnl
Copy link
Copy Markdown
Member

@jrfnl jrfnl commented Mar 9, 2022

... in light of the PHP 8.1 deprecation of the Serializable interface.

For classes which implement the Serializable interface and need to support both PHP < 7.4 as well as PHP >= 8.1, the only way to avoid a deprecation warning is by implementing both the Serializable interface as well as the PHP 7.4 magic __[un]serialize() methods.

In that case, the sniff should stay silent as the code is cross-version compatible, as for PHP < 7.4, the Serializable interface methods will be used to serialize the object, while for PHP 7.4 and higher, the magic methods will be used.

Includes unit tests.

Fixes #1310

Related to #1299

…n]serialize() methods

... in light of the PHP 8.1 deprecation of the `Serializable` interface.

For classes which implement the `Serializable` interface and need to support both PHP < 7.4 as well as PHP >= 8.1, the only way to avoid a deprecation warning is by implementing both the `Serializable` interface as well as the PHP 7.4 magic `__[un]serialize()` methods.

In that case, the sniff should stay silent as the code is cross-version compatible, as for PHP < 7.4, the `Serializable` interface methods will be used to serialize the object, while for PHP 7.4 and higher, the magic methods will be used.

Includes unit tests.

Fixes 1310
@wimg wimg merged commit 037fdb1 into develop Apr 14, 2022
@wimg wimg deleted the feature/newmagicmethods-dont-throw-warning-for-serializable-with-magic branch April 14, 2022 19:53
@jrfnl jrfnl removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check for magic __serialize() and __unserialize() methods needs to account for Serializable

2 participants