Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75425 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77211 invoked from network); 13 Jul 2014 16:09:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2014 16:09:33 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:52728] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/3C-16748-C3FA2C35 for ; Sun, 13 Jul 2014 12:09:33 -0400 Received: by mail-wg0-f44.google.com with SMTP id m15so3079229wgh.27 for ; Sun, 13 Jul 2014 09:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=EV7dl2l9arfRQe/koI4o9Vh2tBftyQrGpfo+Qhu/uSE=; b=p+axYNTJ/QPHzihdjOtlW71iraeGoHAysBcpcuPB8bkVlnG2J6dptthkHTRSWovq22 KXYpdIFqu7/9SPg2C38wOEQFbNiQiVZXKsUJvkYFewF6fPIL8GVpmpwq8Sp81HiPCZRU eDJToPdCfqvxSYRUMMPDu0w6OvnVRid25hkB4P02sB/8tWaRRRmjejCTe20O7G3DQK6P rRDHxkiA+coxmSWm4DmP515FucLLuftO2jWYGHBuJXNoBE1vg2J8EQmJYh1yhb0ikPb7 R2ATxBwaKtdS/1YvBpeN450R2GBo+wxaDSjiCaj4uXZNNbS7sgp3HLQAYfWEN7CLruv6 GI4A== X-Received: by 10.180.38.14 with SMTP id c14mr5486713wik.43.1405267768857; Sun, 13 Jul 2014 09:09:28 -0700 (PDT) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginm.net. [81.101.201.26]) by mx.google.com with ESMTPSA id d4sm20320816wiy.13.2014.07.13.09.09.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Jul 2014 09:09:28 -0700 (PDT) Message-ID: <53C2AF35.40003@gmail.com> Date: Sun, 13 Jul 2014 17:09:25 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net 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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: rowan.collins@gmail.com (Rowan Collins) On 13/07/2014 16:45, Zeev Suraski wrote: > Even reading Nikita's piece, he's saying he dislikes that option for > 'obvious reasons', but I see nothing obviously wrong with this approach. > [...] 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. I think you're muddling two sections of Nikita's article [1]. The option which is dismissed "for obvious reasons" is "unenforced type hinting" - keywords which do absolutely nothing other than give a literal hint to non-critical tools like documentation and reflection. The next section is about "casting weak type hinting", which is described as "one of the more interesting proposals". It certainly has merit, although in my opinion it's less powerful than the other options in what it adds to the language, as the equivalent userland boilerplate is really minimal (e.g. $foo = (int)$foo). As I've mentioned elsewhere, and indeed was mentioned in Anthony's proposal at the time [2], the addition of warnings on lossy casts is a completely separate issue to the ability to sugar those casts into a function signature. Now, what is being proposed here is effectively "casting strict type hinting", a variant of what Nikita called "strict weak type hinting", with the additional step of actually applying the lossless cast, rather than just asserting that it's possible. This actually provides a lot of functionality which is fiddly to implement in userland, and I can't see a lot of uses for asserting that a cast would be non-lossy, if you're not about to perform that cast (which is what "strict weak type hinting" allows). [1] http://nikic.github.io/2012/03/06/Scalar-type-hinting-is-harder-than-you-think.html [2] http://blog.ircmaxell.com/2012/03/parameter-type-casting-in-php.html -- Rowan Collins [IMSoP]