Re: hex2bin: E_WARNING is too much for odd string?

From: Date: Thu, 27 Jun 2013 01:05:34 +0000
Subject: Re: hex2bin: E_WARNING is too much for odd string?
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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)

« previous php.internals (#67914) next »