Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75421 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71534 invoked from network); 13 Jul 2014 15:45:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2014 15:45:53 -0000 Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.182 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.220.182 mail-vc0-f182.google.com Received: from [209.85.220.182] ([209.85.220.182:46971] helo=mail-vc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C4/1B-16748-0B9A2C35 for ; Sun, 13 Jul 2014 11:45:53 -0400 Received: by mail-vc0-f182.google.com with SMTP id hq11so5543000vcb.13 for ; Sun, 13 Jul 2014 08:45:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type; bh=oIb+agj6Ppkq4pgEwLo/2ZoSFLq6L+fYnpKkOCYaFE8=; b=ZX9RTlbXEB5ockwV+isHyxoWudV3ydTNSOnM5sxDDDV+HfqqVFfeectXOuoxZ28znU JFVE/dNOlHq5I/zZWwxiTBZOUzpfEqMuA5LZk2LwPvMxsyudaXBYtTW6ez3hzmqeOvWp nhOcfkzSCuxHCGly0cSbnJVRlt0gOp038rzfaZyaNc/61cVf77e1lUmzCOByVEJZ5wZN mXSLAgUbaMeZlnnb8xRvR5uhKP6/Qn1b8PPzUnpfNzad7xvoZKjCEC3H0GfFVQsT5jBY wMeao2D1AQsC0ebCtP97MM6j8ooAZ8iyHgt+pBwgzDTM9ApakFOJflyJuA5ocCbQ5VE5 /J6Q== X-Gm-Message-State: ALoCoQnsL+PdleknxILS9cR7GATJ5C3XuomCzIqw0BLJyV4jTOIUFBL0fVvCyhOhtScfKBWJr+wE7eVzqc4wfum3qGPJDQ+UMrBYR5iQ3+EXnp6t1CWTT3y8XNgrBMPC2x7xNrGGBvVG X-Received: by 10.58.11.234 with SMTP id t10mr11341531veb.8.1405266350217; Sun, 13 Jul 2014 08:45:50 -0700 (PDT) References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <027E65EF-C4FC-474C-92BB-D99EFADDEEED@ajf.me> <53C29EE4.3090808@gmail.com> <63e5b1c38d6e0c5111987e78d9b59be3@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJuUFVOlGiX172RfpkkW7aXwqSXwwOWY2SKAql1dl4CVdDzGgKRSJF6AWT2/k4CFsPBuAJBAJoIAfHW5ZKZyhL0MA== Date: Sun, 13 Jul 2014 18:45:49 +0300 Message-ID: To: Andrea Faulds Cc: Jocelyn Fournier , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: zeev@zend.com (Zeev Suraski) > -----Original Message----- > From: Andrea Faulds [mailto:ajf@ajf.me] > Sent: Sunday, July 13, 2014 6:19 PM > To: Zeev Suraski > Cc: Jocelyn Fournier; PHP internals > Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) > > 1. Casting type hints > 2. Strict type hints > 3. Scalar type hinting with casts > > (There are others, but I won't talk about them) > > I'm not of the opinion that the first option, where we just cast and never > error, is ideal. It does ensure the values are of the correct type when they get > to you, so it keeps PHP's type juggling, but it is unlikely to catch bugs where > the wrong value has been passed. Let's stop for a moment right here. If we emit notices, or even new E_CAST, do we not get the exact same ability to catch errors you'd get from E_RECOVERABLE_ERROR? Even reading Nikita's piece, he's saying he dislikes that option for 'obvious reasons', but I see nothing obviously wrong with this approach. In fact, it gives you the full power of ensuring the correct types in the 'inner code', allows you to catch 'bad conversions' if you wish to (many don't, but I agree some and perhaps many would), and allows you to use this feature in the most widespread way possible while minimizing the amount of code you need to write in order to use it (no inflation in necessary try/catch blocks). Unlike what's suggested in that piece, it's not equivalent at all to docblocks, as it is in fact enforced, and as you said, has the benefit of being able to write the 'inner code' without worrying about the input types. Whether we go for option #1 or #3 doesn't change the amount of bugs you can find *if you wish to, unless I'm missing something. Option #3 forces you to explicitly deal with 'error' situations (which may or may not be errors), while option #1 leaves it up to the developer whether he wants to write 'E_CAST clean' code or not, similarly to E_STRICT (assuming we introduce E_CAST, we can choose an existing error level too). Zeev