Req #80202 [NEW]: request "y" and "n" support for FILTER_VALIDATE_BOOLEAN
| From: | divinity76 at gmail dot com | Date: | Thu, 08 Oct 2020 11:21:04 +0000 |
| Subject: | Req #80202 [NEW]: request "y" and "n" support for FILTER_VALIDATE_BOOLEAN | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229470@lists.php.net to get a copy of this message | ||
From: divinity76 at gmail dot com
Operating system:
PHP version: Next Minor Version
Package: Unknown/Other Function
Bug Type: Feature/Change Request
Bug description:request "y" and "n" support for FILTER_VALIDATE_BOOLEAN
Description:
------------
i wish for FILTER_VALIDATE_BOOLEAN to support "y" (for bool(true)) and
"n" (for bool(false))
in shell scripts, "y" and "n" often mean "yes" and "no" for
yes/no
questions in shell scripts, as an example, the GNU Coreutils "yes"
program (usually located at /usr/bin/yes ,
https://man7.org/linux/man-pages/man1/yes.1.html
)
will spam "y\n" indefinitely, to be used in shell scripts that ask for
yes/no questions, for example "yes | sensors-detect" to tell lm-sensors'
sensors-detect to scan for all supported sensors,
so when writing php shell scripts asking for yes/no, it's a shame that
FILTER_VALIDATE_BOOLEAN doesn't support y/n, now one has to write
something like
<?php
$confirm = readline("confirm: ");
$confirm = ((strtolower($confirm)) === "y" ? true :
((strtolower($confirm)) === "n" ? false : (filter_var($confirm,
FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))));
if($confirm === null){
"error didn't understand blah blah";
}
?>
instead of
<?php
$confirm = readline("confirm: ");
$confirm = filter_var($confirm, FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE);
if($confirm === null){
"error didn't understand blah blah";
}
?>
Test script:
---------------
<?php
var_dump(
filter_var('y', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
filter_var('n', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
);
Expected result:
----------------
bool(true)
bool(false)
Actual result:
--------------
NULL
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=80202&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80202&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80202&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80202&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80202&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80202&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80202&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80202&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80202&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80202&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80202&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80202&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80202&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80202&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80202&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80202&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80202&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80202&r=mysqlcfg