PHP 8.1: New PHPCompatibility.Interfaces.RemovedSerializable sniff#1330
Merged
PHP 8.1: New PHPCompatibility.Interfaces.RemovedSerializable sniff#1330
Conversation
This was referenced Mar 9, 2022
Member
Author
|
I need to investigate the test failure. It may well be that this sniff needs PHPCSUtils 1.0-alpha4. |
New sniff which addresses the following deprecation in PHP 8.1: > **Implementing Serializable without `__serialize()` and `__unserialize()`** > > Either only the new methods should be implemented, if no support for PHP prior to version 7.4 is provided, or both should be implemented. This sniff will throw a warning when a class implements the `Serializable` interface, but does not implement the magic `__serialize()` and `__unserialize()` methods. The sniff contains a `public` `$serializableInterfaces` property for users to provide their own list of additional interfaces (which extend the `Serializable` interface) to scan for. If the sniff comes across an interface declaration extending the `Serializable` interface and the interface is not in the user provided `$serializableInterfaces` list, a warning will be thrown for the user to add the interface to the property via a custom ruleset. Additionally, when the `testVersion` has a minimum PHP version of `7.4` or higher, an additional check is executed: * For interfaces directly extending `Serializable` AND containing a declaration of both the `__serialize()` as well as the `__unserialize()` magic method, thus enforcing the implementation of these methods in classes implementing the interface, a warning will be thrown that the extension of the `Serializable` interface can be removed. * For classes which implement the `Serializable` interface AND contain a declaration of both the `__serialize()` as well as the `__unserialize()` magic method, a warning will be thrown that the implementation of the `Serializable` interface can be removed. Includes unit tests. Includes updating the section about available custom properties in the README. Refs: * https://www.php.net/manual/en/migration81.deprecated.php#migration81.deprecated.core.serialize-interface * https://wiki.php.net/rfc/phase_out_serializable * https://www.php.net/manual/en/class.serializable.php * https://www.php.net/manual/en/language.oop5.magic.php#object.serialize * php/php-src#6494 * php/php-src@3e6b447
fd52b76 to
6558b5c
Compare
Member
Author
|
Fixed it. Had nothing to do with PHPCSUtils, but was related to the fact that this sniff has a custom property which can be set from a ruleset and the tests using that custom property. |
wimg
approved these changes
Mar 19, 2022
|
HI Do we have plan to release new version to check for pHP compatibility? |
Member
|
A new version will come when it is ready. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New sniff which addresses the following deprecation in PHP 8.1:
This sniff will throw a warning when a class implements the
Serializableinterface, but does not implement the magic__serialize()and__unserialize()methods.The sniff contains a
public$serializableInterfacesproperty for users to provide their own list of additional interfaces (which extend theSerializableinterface) to scan for.If the sniff comes across an interface declaration extending the
Serializableinterface and the interface is not in the user provided$serializableInterfaceslist, a warning will be thrown for the user to add the interface to the property via a custom ruleset.Additionally, when the
testVersionhas a minimum PHP version of7.4or higher, an additional check is executed:SerializableAND containing a declaration of both the__serialize()as well as the__unserialize()magic method, thus enforcing the implementation of these methods in classes implementing the interface, a warning will be thrown that the extension of theSerializableinterface can be removed.Serializableinterface AND contain a declaration of both the__serialize()as well as the__unserialize()magic method, a warning will be thrown that the implementation of theSerializableinterface can be removed.Includes unit tests.
Includes updating the section about available custom properties in the README.
Refs:
Related #1299, #1310