Re: hex2bin: E_WARNING is too much for odd string?
Hi all,
I've sent pull request for PHP-5.5 branch.
https://github.com/php/php-src/pull/369
It's simple 1 liner removes E_WARNING for invalid length.
Are there any objections?
If not I'll merge it to PHP-5.5 and master, then update docs.
--
Yasuo Ohgaki
[email protected]
2013/6/27 Yasuo Ohgaki <[email protected]>
> Hi all,
>
> hex2bin raises E_WARNING for odd length hex strings from PHP 5.4.1.
> http://jp2.php.net/manual/en/function.hex2bin.php
> However, just returning FALSE is easier for programmers.
>
> Current behavior requires additional length check for bad hex to prevent
> E_WARNING.
>
> $str = 'abZ';
> if (strlen($str)%2) {
> // BAD hex - invalid length
> } else if (hex2bin($str) {
> // BAD hex - invalid char
> }
>
> Instead, it would better that hex2bin() just returns FALSE for invalid
> hex, IMHO.
>
> $str = 'abZ';
> if (strlen($str)%2) {
> // BAD hex - invalid length or char
> }
>
> I can understand current behavior as BC. However, it would better cleanup
> bad spec sooner or later.
>
> PHP 5.4: Raise E_ERROR and return FALSE for invalid length.
> PHP 5.5: Just return FALSE.
>
> or
>
> PHP 5.4: Keep current behavior
> PHP 5.4: Riase E_ERROR and return FALSE for invalid length.
> PHP 5.5: Remove E_ERROR.
>
> Any ideas?
>
> --
> Yasuo Ohgaki
> [email protected]
>
Thread (21 messages)