Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75993 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53056 invoked from network); 24 Jul 2014 07:22:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2014 07:22:45 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.51 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.192.51 mail-qg0-f51.google.com Received: from [209.85.192.51] ([209.85.192.51:61177] helo=mail-qg0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/90-48436-344B0D35 for ; Thu, 24 Jul 2014 03:22:44 -0400 Received: by mail-qg0-f51.google.com with SMTP id a108so2780512qge.10 for ; Thu, 24 Jul 2014 00:22:44 -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:content-transfer-encoding; bh=jT/ksnswais9JW6xTV3gNtaNYjvDlB7guWYhwauuMio=; b=g/g/a4VLKu0nAIjmGtCgwRmJc+6mswTbqIISvsSCba2B/HDKWrnVl87yfNXRrnvZHk v1m7JAV7YTDhoc/vOJ0aiuw+/mkEZu+bHgsUu/6afAiHmVBwq4Gn8uArgWvvKEAkJTeP EogocdtWUihkKSq40YdEk+740gKq1OA3jaNwsCR6QWGypTHUL6pI5FNw9WJmq9Sa3y/x ij986wemwhYd6cb6nEenbdSf1IlmNFtAS1quah4yzSbzb2648naZklqiy7ZGagFWWj4B Vp8wN1hbvOVoPit/bowUJY4xAEO1NIOzyH/cS8CD/IBjN+Hww+QvuvbDsQryAqPjQgi/ BOwA== MIME-Version: 1.0 X-Received: by 10.224.137.193 with SMTP id x1mr12388472qat.0.1406186564425; Thu, 24 Jul 2014 00:22:44 -0700 (PDT) Received: by 10.140.24.54 with HTTP; Thu, 24 Jul 2014 00:22:44 -0700 (PDT) In-Reply-To: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> Date: Thu, 24 Jul 2014 09:22:44 +0200 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: pierre.php@gmail.com (Pierre Joye) hi Andrea, On Sun, Jul 13, 2014 at 3:57 AM, Andrea Faulds wrote: > Good evening, > > PHP=E2=80=99s type hinting system is rather incomplete as it does not sup= port scalars, only arrays, callables and objects. In 2012, Anthony Ferrara = created an RFC which proposed type hinting for scalar types (int, float, bo= ol, string and resource) with casting, with behaviour nearly the same as th= at of zend_parse_parameters. Sadly, he later left PHP internals and withdre= w his RFCs. > > Since I am very much in favour of scalar type hints, I=E2=80=99ve updated= the patch to master and made some minor improvements, and I am re-opening = the RFC with the intent to try and get it into PHP 5.7. The patch is mostly= there. It needs some more tests and there are some edge cases I need to de= al with, but it otherwise works, and I expect I can finish fixing it up ver= y soon. > > The RFC is here: https://wiki.php.net/rfc/scalar_type_hinting_with_cast > > A pull request is here: https://github.com/php/php-src/pull/717 > > I=E2=80=99m hoping I can get this into PHP 5.7. I think scalar type hinti= ng would be a valuable addition to PHP=E2=80=99s existing type hinting syst= em. very nice work, thanks! Some comments or wishes. I know these points have been discussed already in the other threads but I still think it is worth posting that here and (re) consider it. To me argument types handling should match what we already do for classes, strict handling. I asked many users at various conferences or large companies using PHP and this is also what they wish. Indeed I am not saying that all users wish that (who am I to say that? :) but I feel like there is a large majority expecting this behavior. The argument saying that it is not the PHP way is somehow incorrect here, given that we already do that for classe. The type jungling makes sense in implementations, as it always was but argument passing and validation have been a source of pain since very long. I could imagine one exception with the "numeric" type, which could accept anything and got converted to integer/numeric values, like "1235ab" or other weird things. Cheers, --=20 Pierre @pierrejoye | http://www.libgd.org