Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68015 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59402 invoked from network); 29 Jun 2013 01:54:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2013 01:54:32 -0000 Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.178 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.212.178 mail-wi0-f178.google.com Received: from [209.85.212.178] ([209.85.212.178:50945] helo=mail-wi0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/F3-37409-65E3EC15 for ; Fri, 28 Jun 2013 21:54:31 -0400 Received: by mail-wi0-f178.google.com with SMTP id k10so1368179wiv.5 for ; Fri, 28 Jun 2013 18:54:28 -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=Vg0CEUTZkh+x1ikTLPCiU88Y4ofhrUKCu/imQFLsVJE=; b=JupAPtLTyO7tNyKoWy7UI4SxjWwkNlezIuwSNjS+D/KiJjKhfETF1uZYPH8lXVVZhl YyUJxg1lkvhyQ3kYTB1v9QmvjMQzQefXzKd83eQUwOC0MD+pgQB6IqN2ZhgyWy5gHVrU bqt9hsUmZR4trXq/OWgCCoo064GTjkaIAjU/hvHZb1uTSVcL3Wqzz2yWL43cplrQW1lY tR4QW9UevlvMvWMM/kF4eYPCuNmZOOngQAWmA3/v4gvY+Ww3+WHoAFmv/bZZuH/ChBJX e9oVIfecgoNCNGt2eQ9CFLQveBsKF3iFy+aNWkQ2KjHW9DPyiqsbsdo43Nc8FyUWgKhk v/IQ== MIME-Version: 1.0 X-Received: by 10.180.108.50 with SMTP id hh18mr3678574wib.39.1372470867946; Fri, 28 Jun 2013 18:54:27 -0700 (PDT) Received: by 10.227.108.5 with HTTP; Fri, 28 Jun 2013 18:54:27 -0700 (PDT) In-Reply-To: References: <51CD5580.50103@gmail.com> Date: Fri, 28 Jun 2013 21:54:27 -0400 Message-ID: To: Yasuo Ohgaki Cc: =?ISO-8859-2?Q?Leszek_Krupi=F1ski?= , PHP Internals Content-Type: multipart/alternative; boundary=e89a8f3b9fdd8c753904e04146b9 Subject: Re: [PHP-DEV] Re: hex2bin: E_WARNING is too much for odd string? From: theanomaly.is@gmail.com (Sherif Ramadan) --e89a8f3b9fdd8c753904e04146b9 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jun 28, 2013 at 9:41 PM, Yasuo Ohgaki wrote: > Hi Sherif, > > The problem is that current code 'returns false for invalid hex' while it > 'returns false and E_WARNING for invalid length'. > > We may choose behavior for invalid inputs > - return false always > - return false and raise E_WARNING always > > Mixing them up is not good, especially in the same function. IMHO. PHP has > enough inconsistency. We should try to remove inconsistency much as > possible. Besides the change will not break code as long as it is used as > it should be. > > If we tried to fix all of PHP's functions to either return false always or return false and raise errors always we'd have to fix every single PHP function there is since there's absolutely no consistency there as it is. Different functions handle failure differently, and not all functions report every possible error they may encounter. Take functions like file_get_contents, for example, where it wraps other API functions that could RETURN_FAILURE and/or trigger the error handler, and file_get_contents isn't even documented to raise those errors in some cases. I see these as two separate problems. The first problem is clearly a design problem (but we can't really do much about that in the short term). The second is a documentation problem. Beyond that there are users that don't clearly understand the behavior of some functions due to the previous two reasons. > Considering the use case of hex2bin(), it will not handle external inputs > in most cases. Therefore, it's better to raise errors invalid inputs. Do > you prefer not to raise errors? > Considering the fact that we have a discussion in the bug report mentioned earlier (and it was an extensive discussion because not only were our users confused but even our core developers were confused if you read the responses in that bug report), I would prefer that we leave the function the way it is. The error was added for a very specific reason. People thought it was doing what pack('h*', $hex) does, and clearly it wasn't. So the documentation was also updated to make note of this and explain it to the user, along with the helpful error message to indicate that hex2bin('f') would not work. I don't think there was ever any expectation for the user to do something like hex2bin('Hello World') and expect any kind of sensible result. The error really does not inform them of anything useful. > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > > --e89a8f3b9fdd8c753904e04146b9--