Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67914 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69212 invoked from network); 27 Jun 2013 01:06:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 01:06:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.173 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.173 mail-lb0-f173.google.com Received: from [209.85.217.173] ([209.85.217.173:59312] helo=mail-lb0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/83-51393-9009BC15 for ; Wed, 26 Jun 2013 21:06:18 -0400 Received: by mail-lb0-f173.google.com with SMTP id v1so116891lbd.18 for ; Wed, 26 Jun 2013 18:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:content-type; bh=WhCuN57kzJlp0UmxzwmQIrV1VmFn6wRxuQjThuDl/8o=; b=oKreSy5Sys9efWi+rDxeaoJN8PXjPMRVWBlvZmo8O0x6UuDpksnq0gyNB+AEjUNAQ4 +LEGOVoDHwR77mIyKsyGMsTb2v1G/e8bOrL58ZeRVBvCdSOBGTZ9wNJffjYSo+7aCDDw uXGYRPik4qzijyn5XAUbuGFsNcxf3hdxufEtJYq+ViZWzuBwgOtapOZNLunV4ztN1keF 41XJg/V/2QoqVbLGkH14N8wOlmK8dx4r7Ivt7DDP0z4xh5vhP//tP2WB174ZymdPfEdU HDfbos3nzCoUEqRcITssnCb4QaVEHMDkH+vmiwDlow2vJ7c9LnWEm4nDANJVBvXcU29E 0xGQ== X-Received: by 10.152.29.227 with SMTP id n3mr3010594lah.43.1372295174659; Wed, 26 Jun 2013 18:06:14 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.4.233 with HTTP; Wed, 26 Jun 2013 18:05:34 -0700 (PDT) In-Reply-To: References: Date: Thu, 27 Jun 2013 10:05:34 +0900 X-Google-Sender-Auth: mrlpaVIS1SK_SpqSjbFWzTvw804 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e0158c76c69a62b04e0185efc Subject: Re: hex2bin: E_WARNING is too much for odd string? From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e0158c76c69a62b04e0185efc Content-Type: text/plain; charset=ISO-8859-1 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 yohgaki@ohgaki.net 2013/6/27 Yasuo Ohgaki > 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 > yohgaki@ohgaki.net > --089e0158c76c69a62b04e0185efc--