Skip to content
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

Add missing return types to magic methods #50842

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Jul 1, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? no
Deprecations? yes
Tickets -
License MIT
Doc PR -

I promise, these 72 methods really are the last methods that did not have a return type already 🙃

@carsonbot carsonbot added this to the 6.4 milestone Jul 1, 2023
@wouterj wouterj force-pushed the magic-methods-return-types branch 2 times, most recently from 463bb02 to b3dc556 Compare July 1, 2023 12:05
@@ -149,11 +149,17 @@ private function sendToElasticsearch(array $records): void
$this->wait(false);
}

/**
* @return never
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of the added never types to sleep+wakeup. To me, this is motivated by the internal implementation, but the implementation shouldn't drive the contract. Since these methods are magic, they're not supposed to be called by any userland code directly. This more tailored type doesn't serve any purpose. Actually, it only prevents potential child classes from providing their own implementation if they'd like to. I don't have a use case in mind, but that's not a reason to close the API here to me.

Copy link
Member Author

@wouterj wouterj Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also a bit hesitant to add never as a return type, as it blocks the user from implementing any other behavior.

But in this case, I added them because all these sleep+wakeup calls are never to prevent insecure deserialization. I thought it would be a good idea to actually prevent user-code from loosing this requirement, as that could unknowingly make them vulnerable for this type of attacks.

If you still disagree, I'm open to reverting these to array and void again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure and I understand that. That's on the edge of the open/closed principle, just a bit too much on the closed side to me :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that the security argument doesn't stand: implementing __serialize still allows working around never; this adds to "open" side.

@nicolas-grekas
Copy link
Member

Thank you @wouterj.

@nicolas-grekas nicolas-grekas merged commit 7147751 into symfony:6.4 Jul 5, 2023
4 of 9 checks passed
@wouterj wouterj deleted the magic-methods-return-types branch July 5, 2023 10:17
PhilETaylor pushed a commit to PhilETaylor/symfony that referenced this pull request Sep 6, 2023
…erj)

This PR was merged into the 6.4 branch.

Discussion
----------

Add missing return types to magic methods

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | -
| License       | MIT
| Doc PR        | -

I promise, these 72 methods really are the last methods that did not have a return type already 🙃

Commits
-------

6b27001 Add missing return types to magic methods
This was referenced Oct 21, 2023
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.

None yet

4 participants