Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79062 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53907 invoked from network); 21 Nov 2014 03:02:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Nov 2014 03:02:59 -0000 Authentication-Results: pb1.pair.com header.from=adam@adamharvey.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adam@adamharvey.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adamharvey.name designates 209.85.213.179 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.213.179 mail-ig0-f179.google.com Received: from [209.85.213.179] ([209.85.213.179:51535] helo=mail-ig0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/63-32541-26BAE645 for ; Thu, 20 Nov 2014 22:02:58 -0500 Received: by mail-ig0-f179.google.com with SMTP id r2so3979720igi.12 for ; Thu, 20 Nov 2014 19:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adamharvey.name; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=LRdnCo2MH5leQQYp2wQsLnmwAip5MNQ9VyTS55eycDE=; b=zcdNGVio3sYjfRXO1lHgSPm1OWidlvZwFeMMI5UAz50Nu8HtVlfONChRL6XOVuZofc 1seNH56OaeX2pGSLNMNUwdmgNdTLUxM/M6YZYlJpVSOksTF3qVZZBSiXJd2oIbtBCJN7 vZ07onARJYlo30sJctbO6hmuug/VaiU9MVLBM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=LRdnCo2MH5leQQYp2wQsLnmwAip5MNQ9VyTS55eycDE=; b=jv+0G9CGknerL6Dp/yB2Q9GVZgy+hfEii7zJG5U7Wf9pvb9OUTkGk+IQ/FKxWb1Fir QT29/LN9xz4zP12+gP3UauvrekMtgID2Lt8FUvYQZ9mDBn78QBUXDmzCU3CjdetXKHnr GwD7QAwXL+o8crYWF9ErJPxvJsPzBkYslBvKwOP0PUwpiD8NVOO30dE125A3EZIaJIER TOZVjaj1N0XJU/Zd9Tb3rbXpM69GHFJH6u0fspHXyUO/rRS3xh+s6JIq8jhJ7Gxu8sqI C4FpCCU2TppA3Z0ZpeVtYWKO0awVF3YENyaw79gwhQV8pcDKG6pGm9bs0eR6d4jIXdhs 2D9w== X-Gm-Message-State: ALoCoQka4r//1+NY50HxY5n5AN8qwKM9AL+obEjIhoau2GF8LUh0WMH1v5LO8JyjbWDszJhUQXSR X-Received: by 10.50.131.199 with SMTP id oo7mr12867695igb.42.1416538974017; Thu, 20 Nov 2014 19:02:54 -0800 (PST) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.42.86.129 with HTTP; Thu, 20 Nov 2014 19:02:33 -0800 (PST) In-Reply-To: <5A250A28-F5C2-4FF1-B144-C19B2220EADC@ajf.me> References: <5A250A28-F5C2-4FF1-B144-C19B2220EADC@ajf.me> Date: Thu, 20 Nov 2014 19:02:33 -0800 X-Google-Sender-Auth: wp9LdZFGsz-PQTLtjMf1GyGGHMU Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE][RFC] Safe Casting Functions From: aharvey@php.net (Adam Harvey) On 20 November 2014 18:06, Andrea Faulds wrote: > >> On 21 Nov 2014, at 00:45, Adam Harvey wrote: >> >> On 19 November 2014 13:57, Levi Morrison wrote: >>> - The RFC does not address how this is different from >>> FILTER_VALIDATE_* from ext/filter. I know there was a mention of this >>> on the mailing list, but the RFC should say why a tool that already >>> exists to solve this kind of problem is insufficient, especially when >>> it is enabled by default. > > While that was true when Levi said it, the RFC *does* address this now. That's fair =E2=80=94 I read the RFC again when it first came up for vote, = in my defence, but wanted some time to think about it. I should have re-read it before actually voting. Sorry about that. The clunkiness of the filter API is a valid point, although I don't think unconditionally adding a bunch of unnamespaced functions =E2=80=94 wh= ich can be implemented in userspace just fine =E2=80=94 is the right way of dealing with it. (I've snipped your rationale and example. Thanks for writing it =E2=80=94 I don't necessarily agree with it, but it's a good explanation of your thinking, and probably something that would have helped the RFC.) >>> - PHP suffers a lot from function bloat and this RFC provides >>> multiple functions that do the same thing but differ only in how they >>> handle errors. A simple validation of "can this be safely cast to an >>> integer without dataloss?" avoid the issue entirely and would be fewer >>> functions. >> >> +1: the idea of adding two sets of identical functions except for how >> they signal errors isn't one I like. > > The problem is that it=E2=80=99s the least bad of the available options. I disagree. To my mind, the best option right now (barring the status quo, which realistically I'd prefer) would be the try_* functions only. They line up with how ext/standard (and pretty much all of PHP other than a smattering of OO functions and SPL) signal errors, and avoid duplication. I don't really fancy explaining the difference between to_* and try_* in ##php to a new developer. PHP may be a mishmash of undesigned APIs in places, but that doesn't mean we should dump fuel on the fire by adding two parallel APIs that are named obscurely and differ only in how they signal errors. >> Derick raised a good point elsethread: this is really tied into how we >> want to signal errors in PHP 7. If we switch to exceptions, then let's >> figure out a plan of attack and switch to exceptions everywhere, not >> just in the odd function here and there. If we don't, then the to_* >> functions shouldn't be added. > > This isn=E2=80=99t a switch, though, these are new additions. We already = have exceptions in a few places in core, and there=E2=80=99s nothing wrong = with new additions using exceptions if and when appropriate. The question i= s over how to deal with legacy code. There's no function in php-src today that throws an exception outside of an OO context. (Indeed, if you go through the various classes and methods in php-src, I suspect even _in_ an OO context the majority of errors are signalled via return values or PHP errors.) Right now, the standard for appropriateness when adding an exception is pretty much "is this an error generated in an OO context"? This clearly isn't. To be clear: if a way could be designed to do it without shredding BC, I'd be ecstatic if we deprecated our current error handling system entirely in favour of exceptions in PHP 7. But that's not the standard right now, and an unrelated RFC like this isn't the place to make that decision. > In this specific case, I suppose the other option would have been to thro= w an E_RECOVERABLE_ERROR. But exceptions can be handled easier, and so I do= n=E2=80=99t see a particular reason why it shouldn=E2=80=99t throw an excep= tion. Why would you throw an E_RECOVERABLE_ERROR? The error's been signalled: the function returned NULL, rather than an int/float/string. Adam