|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-10-16 05:12 UTC] lucas at threeamdesign dot com
Description: ------------ The docs say it returns false on failure but it returns null when the first argument is not a string (except objects with __toString() ). The function should be made consistent. People who are aware of this quirk will likely be using a ($val === false || $val === null) test, and people who aren't will likely have only ($val === false). Making it return false wouldn't be perfectly backwards-compatible, but would fix more problems than it causes because failure goes undetected if only the latter test is used. If the quirk must remain for compatibility, at least update the docs. Test script: --------------- <?php var_dump(hex2bin(array())); Expected result: ---------------- Warning: hex2bin() expects parameter 1 to be string, array given in foo.php on line 1 bool(false) Actual result: -------------- Warning: hex2bin() expects parameter 1 to be string, array given in foo.php on line 1 NULL PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 19:00:01 2025 UTC |
This is because "return;" is called when there is parameter mismatch. hex2bin() is not the only one, but there are MANY of them. What should we do with this? It would be cleaner if we return FALSE for all parameter mismatch. Any comments? /* {{{ proto string hex2bin(string data) Converts the hex representation of data to binary */ PHP_FUNCTION(hex2bin) { char *result, *data; size_t newlen; int datalen; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &datalen) == FAILURE) { return; }