Skip to content

fix: use native PHP truthiness for condition evaluation in when()/whenNot() #9576

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

Merged
merged 1 commit into from
May 26, 2025

Conversation

michalsn
Copy link
Member

Description
This PR fixes a bug where the when() and whenNot() methods did not treat certain falsy values like 0, '0', null, and empty arrays consistently with native PHP conditionals.

The condition checks are now explicitly cast to boolean using (bool), ensuring consistent and expected behavior across all falsy and truthy values.

Fixes #9575

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label May 23, 2025
@michalsn michalsn merged commit 3638a49 into codeigniter4:develop May 26, 2025
50 checks passed
@michalsn
Copy link
Member Author

Thank you @lonnieezell and @paulbalandan

@michalsn michalsn deleted the fix/when-condition branch May 27, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: when() & whenNot() evaluate empty array to true
3 participants