Skip to content

Fix behavior for controller actions with union types #20352

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

chriscpty
Copy link
Contributor

This fixes the behaviour for yii\web\Controller::bindActionParams when a function parameter has a union type.

In effect, this fixes two issues:

  • For a union type that can be a string or a numeric value (such as string|int), if the parameter value is a string containing a numeric value (such as '1'), the result will be the numeric value ((int)1 here) rather than the string.
  • For a union type that can be either an array or a different type (such as int|array), if the parameter value is an array, the controller no longer throws a BadRequestHttpException, fixing "Bad request" for array parameter with union type #20351.
Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues #20351

! fix yii\web\Controller::bindActionParams behaviour for union types
o some refactoring in the process
o cleanup, changelog
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 40.84507% with 42 lines in your changes missing coverage. Please review.

Project coverage is 64.37%. Comparing base (47fb7fc) to head (fee7a56).

Files with missing lines Patch % Lines
framework/web/Controller.php 40.84% 42 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20352      +/-   ##
============================================
- Coverage     64.43%   64.37%   -0.06%     
- Complexity    11445    11468      +23     
============================================
  Files           433      433              
  Lines         37455    37501      +46     
============================================
+ Hits          24135    24143       +8     
- Misses        13320    13358      +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chriscpty
Copy link
Contributor Author

Does codecov only check for coverage with PHP < 8.0 (hence the reduced coverage, because a good part of the added code is only touched in PHP >= 8.0 and is covered by tests codecov doesn't seem to see)?

@samdark samdark requested review from a team April 13, 2025 07:38
@samdark
Copy link
Member

samdark commented Apr 13, 2025

Would you please measure performance impact w/ phpbench if possible?

chriscpty and others added 3 commits May 19, 2025 11:53
- remove needless class_exists call
! fix issue when handling parameter with string type, add according test
@chriscpty
Copy link
Contributor Author

I haven't set up PHPBench for this (and don't have the time to atm), but from some rudimentary testing, it seems like there's no performance impact when no union types are used, but for an action with two union type parameters, it took about 1.5x the time the old version took.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants