Req #73810 [NEW]: hex2bin should return false or throw an exception instead of an E_WARNING
| From: | francesco dot montanari at outlook dot com | Date: | Sat, 24 Dec 2016 15:05:43 +0000 |
| Subject: | Req #73810 [NEW]: hex2bin should return false or throw an exception instead of an E_WARNING | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-206192@lists.php.net to get a copy of this message | ||
From: francesco dot montanari at outlook dot com
Operating system: All
PHP version: 7.1.0
Package: Unknown/Other Function
Bug Type: Feature/Change Request
Bug description:hex2bin should return false or throw an exception instead of an E_WARNING
Description:
------------
I agree with this thread:
http://grokbase.com/t/php/php-internals/136tjmm93r/hex2bin-e-warning-is-too-much-for-odd-string
"a function that is supposed to deal with external inputs is better if
it returns FALSE without error"
Now we have to do something like this:
$binaryUuid = @hex2bin(str_replace('-', '', $_GET['uuid']));
if($binaryUuid === false) {
// Show an "Invalid UUID" error
}
but using the "@" operator is considered bad practice, and validate the
input BEFORE passing it to hex2bin is out of discussion because it will
slow down the app for nothing (for example I receive 10 million valid
uuid per day, and only about a hundred invalid ones).
Returning false, or throwing a catchable exception would be a better
behaviour
--
Edit bug report at https://bugs.php.net/bug.php?id=73810&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73810&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73810&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73810&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73810&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73810&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73810&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73810&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73810&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73810&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73810&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73810&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73810&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73810&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73810&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73810&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73810&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73810&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73810&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73810&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73810&r=mysqlcfg