FILTER_VALIDATE_BOOLEAN returns wrong result for null
Nobody has claimed this yet.
- #3797 by @DanielEScherzer — closed without merging
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Description
The following code:
<?php
var_dump(filter_var(null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
Resulted in this output:
bool(false)
But I expected this output instead:
null
Documentation states
Returns true for "1", "true", "on" and "yes". Returns false otherwise.
If FILTER_NULL_ON_FAILURE is set, false is returned only for "0", "false", "off", "no", and "", and null is returned for all non-boolean values.
So the expected result should return null as null is not '0', 'false', 'off' or ''.
PHP Version
php 8.0.28
Operating System
Debian
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the FILTER_VALIDATE_BOOLEAN documentation and the reported filter_var example. Compare the documented FILTER_NULL_ON_FAILURE behavior with the PHP 8.0.28 output; done means the relevant documentation or example accurately reflects the confirmed behavior. A linked pull request and the existing discussion should also be checked before starting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100