Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68004 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92405 invoked from network); 28 Jun 2013 09:38:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2013 09:38:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wg0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:54749] helo=mail-wg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/9D-34034-AA95DC15 for ; Fri, 28 Jun 2013 05:38:51 -0400 Received: by mail-wg0-f41.google.com with SMTP id y10so1284758wgg.2 for ; Fri, 28 Jun 2013 02:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZS9Beu+p0ze83Xv6uRZ8RKIThLs+Qj97wzDZIYzerLs=; b=D6lAJmLKjq3QTYIT+E2+QoaNDhczt3zTE7AWWQ8fbxtMuRFozNamKiuy1ImjAtSLJS ID7k9Q53a4cYbUIfvQ5mc/pNdUFiOWOUGgxIIjEHk0uMCqEzCvkDIuL32TOwJczOGjw0 y7Z4Nh2oMWbF1cvV2mx44hnC2psxxP79HSWkujlVpd/PotXNVPjCU0orA3lYBUnjVgFS 3V7bvJ8/W7BrUseYswKdhjjCFmcRayk3RkmZoJNADFfS4mYk/h1eW4kGtED6KLpHurqu SygSq/B7WtPcEU3snVQ+BGySPm5qAvSxwumSFZfgO7NCbW3C+pZUmFXXiSOU53brlRzv rkXA== MIME-Version: 1.0 X-Received: by 10.194.119.195 with SMTP id kw3mr9076523wjb.64.1372412327906; Fri, 28 Jun 2013 02:38:47 -0700 (PDT) Received: by 10.227.60.205 with HTTP; Fri, 28 Jun 2013 02:38:47 -0700 (PDT) In-Reply-To: <51CD5580.50103@gmail.com> References: <51CD5580.50103@gmail.com> Date: Fri, 28 Jun 2013 05:38:47 -0400 Message-ID: To: =?ISO-8859-2?Q?Leszek_Krupi=F1ski?= Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e012289464a51ae04e033a5bc Subject: Re: [PHP-DEV] Re: hex2bin: E_WARNING is too much for odd string? From: theanomaly.is@gmail.com (Sherif Ramadan) --089e012289464a51ae04e033a5bc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Jun 28, 2013 at 5:21 AM, Leszek Krupi=C5=84ski = wrote: > On 2013-06-27 03:33, Sherif Ramadan wrote: > >> On Wed, Jun 26, 2013 at 9:05 PM, Yasuo Ohgaki wrote= : >> >> 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? >>> >>> Yes, I object to removing the error in the same breath we're arguing f= or >> consistency. 5.4.0 through 5.4.3 (no error), 5.4.4 through 5.4.16 (error= ), >> 5.5.0 (error), 5.5.1 (no error)??? What kind of consistency is this? >> >> I thought you wanted to add an extra error for malformed hex, which I >> would >> have been fine with, but removing the error entirely? The error is usefu= l. >> It informs the user that they may have buggy code since the function is >> clearly documented to expect even length hex encoded strings. >> > > In my opinion generating E_WARNING is too severe. Passing improper string > to hex2bin does not necessary mean "buggy code". If the string is eg. fro= m > external input, why should I check if it's a well formed hex string if th= e > function does this anyway? I think E_NOTICE + returning false is enough. > > And about consistency... I don't know the rationale behind adding E_ERROR > in recent versions, but if the situation is bad, it should be fixed, not > proliferated to next versions. Yes, it'd better if the change was better > thought, but the milk has spilled. > > To be fair, the only reason we ended up adding an E_WARNING in the first place is because someone raised a concern that they had the wrong expectation about what the function does. As far as I can tell, there is no reason that the user would believe hex2bin (a pretty descriptive function name) should accept anything other than proper hex notation. Meaning that returning false on failure is fair when the string is not valid hexadecimal encoding. The issue of having odd or even length hexits, however, is a different matter entirely. People (myself included) misunderstood what the function does. The misconception being that this function took a hexadecimal **number** and converted it to a binary **number**, which is not what it does. In such a case it is perfectly acceptable to have something like "f" translate to a valid ASCII character, for example. As is with the case of pack("h1". "f"), or ord(base_convert('f', 16, 10))... This is a fruitless endeavor to complain about consistency in PHP where we are the ones actually creating unnecessary inconsistencies that can't be justified from an objective point-of-view, in my own personal opinion. --089e012289464a51ae04e033a5bc--