Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78216 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8049 invoked from network); 22 Oct 2014 07:46:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2014 07:46:07 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.218.54 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.218.54 mail-oi0-f54.google.com Received: from [209.85.218.54] ([209.85.218.54:41959] helo=mail-oi0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/60-01590-AB067445 for ; Wed, 22 Oct 2014 03:46:06 -0400 Received: by mail-oi0-f54.google.com with SMTP id v63so2306528oia.13 for ; Wed, 22 Oct 2014 00:45:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=bZ6WDycwcLTG5JmUcuqDuQKnu6mM37MO5lxx3U0m8fk=; b=g6N4BGlz6Cjxuxc6B9XTLxUXiCXIG0glFmxjCu6E3leOr3JJWwEzDyewvOWiXpQ8Va q8zm+agxbw7EDyavpgSz+YpsSMJvWei9TSf6pMvKyFvba/XlNSzeAfycXT2dhcV37Sug 27uU03gGFudYCk5vPqaQ6jsz1+pM5k2gpvKhvRNrbpy5+/2+PyCDKxFJpuHN1Khyq7JZ k/hh361g634B2HeIHiv2i0ORMgupa2WCj45ItWtuDo37AlWVSrNHDlkFRghR9RxJRFFs zojn2FfL7yIW9mS0hPjK0ddJme7LQm3zJkDxM1h5310DicSmiCd5wQebyFRHkyxgTNmb BvhQ== X-Gm-Message-State: ALoCoQnKcy0B/5IRKLcPWc86kbFE51bYUcDMllc3g7CYheyw/lXmvjBTEG6dOvYUlA0LmVYtQkEnOSQUYzmrkEYtSdTA7KxBfK8p+yMrLHXQIXLYMxYbBO60VfHtEkcIzySdmBqQ2Nm6B/V6jdPR93v+TyXvTRO8XA== MIME-Version: 1.0 X-Received: by 10.202.197.14 with SMTP id v14mr32707329oif.2.1413963959404; Wed, 22 Oct 2014 00:45:59 -0700 (PDT) Received: by 10.60.70.41 with HTTP; Wed, 22 Oct 2014 00:45:59 -0700 (PDT) In-Reply-To: <866A39C7-6F11-408D-8BCA-594BA22E8569@ajf.me> References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <866A39C7-6F11-408D-8BCA-594BA22E8569@ajf.me> Date: Wed, 22 Oct 2014 11:45:59 +0400 Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a113e3afe86a5880505fe2324 Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions From: dmitry@zend.com (Dmitry Stogov) --001a113e3afe86a5880505fe2324 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Oct 22, 2014 at 2:51 AM, Andrea Faulds wrote: > > > On 21 Oct 2014, at 10:14, Dmitry Stogov wrote: > > > > some notes: > > - it's probably make sense to implement these function as a new > opcode(s) in VM > > That could be an optimisation later, yes. I note that you=E2=80=99ve adde= d > function replacement with opcodes for certain commonly-used functions. We > could make these functions use that. Then they=E2=80=99d still be usable = as > callbacks. > I may help with implementation, if RFC accepted. (It would be better if ZEND_STRLEN, ZEND_TYPE_CHECK, etc were introduced in first place instead of stlen(), is_long() and family). > > - in case of conversion failure it's better to throw exception (to_int(= ) > returning FALSE is a pain). > > I am gradually warming to throwing an exception. An interesting idea I=E2= =80=99ve > had suggested on Twitter was by Matt Parker, who suggested that I add an > optional 2nd argument. Without the argument, it throws an exception. With > an argument, it returns that value (as a default) instead of throwing an > exception. > Together with https://wiki.php.net/rfc/engine_exceptions_for_php7 throwing exceptions would be the best choice. I would make it permanent, (without optional areguments) Thanks. Dmitry. > > -- > Andrea Faulds > http://ajf.me/ > > > > > --001a113e3afe86a5880505fe2324--