-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug][DebugClassLoader] Discourage using the \Serializable interface #30987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm unsure if |
The Also the So I think the question here is more something like : do we want the |
The fact it is third-party or userland code makes no difference as it triggers based on specific markers such as |
The RFC …
https://wiki.php.net/rfc/custom_object_serialization In other words, there is the intention of deprecating the interface some time in the future. There is (to my knowledge) no RFC yet to actually deprecate it. So even if we would see it as the responsibility of |
So let's add a check to enforce this in the |
76591e0
to
e3ed9fc
Compare
@nicolas-grekas I restricted it to the Symfony namespace + I applied your idea to handle interfaces (but will need #31011 for tests to pass). |
e3ed9fc
to
7b10f7c
Compare
@@ -313,6 +316,17 @@ public function checkAnnotations(\ReflectionClass $refl, $class) | |||
return $deprecations; | |||
} | |||
|
|||
if ( | |||
isset($parentAndOwnInterfaces['Serializable']) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be an "is_a" check, so that this is triggered for classes whose parent interfaces extends Serializable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with a is_a
check is that it will trigger for classes extending \ArrayIterator
for example. And we're not gonna stop extending this core class in the core I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas Thanks for your review. I have addressed all comments. This is the last one 😄
e1caa30
to
0f6ada1
Compare
`Exception\FlattenException::getTraceAsString` to increase compatibility to php | ||
exception objects | ||
`Exception\FlattenException::getTraceAsString` to increase compatibility to php exception objects | ||
* added a deprecation for classes and interface that implements or extends the `\Serializable` interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for classes and interfaces that implement or extend
0f6ada1
to
f0e400d
Compare
@fancyweb I rebased + added a 2nd commit on this PR. I did not update tests so that you can inspect the effect of the changes. Please have a look and squash+fix tests if you're OK. Let's discuss it if not. |
@nicolas-grekas I have just checked your implementation. Three initial tests are failing. The failing tests are on "interfaces" cases. With the initial implementation, deprecations are reported on interfaces that extends interface ExtendsSerializable extends \Serializable
{
}
class ImplementsAnInterfaceThatExtendsSerializable implements ExtendsSerializable
{
public function serialize() {}
public function unserialize($data) {}
} With the initial implementation, deprecations are reported on the Also, this implementation does fix the interface ExtendsSerializable extends \Serializable
{
}
class ImplementsAnInterfaceThatExtendsSerializable implements ExtendsSerializable
{
public function __serialize(): array {}
public function serialize() {}
public function __unserialize(array $data): void {}
public function unserialize($data) {}
}
class AnotherClass extends ImplementsAnInterfaceThatExtendsSerializable
{
public function serialize() {}
} Technically, WDYT of those two points? |
@nicolas-grekas I'm doing a tour of my open PR. Is this one going somewhere or should we just close? The amount of time we both spent on this might not be worth it in the end 😄 |
Agreed :) |
#eufossa
The deprecation is triggered only if the class implementing
\Serializable
does not already implement the future serialization mechanism (with__serialize
and__unserialize
).The case we don't handle (yet) is if your class implements an interface that extends
\Serializable
.Needs #30965 and twigphp/Twig#2927 for tests to pass.