Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58801 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29954 invoked from network); 9 Mar 2012 02:58:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2012 02:58:05 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:55596] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/63-10820-CB1795F4 for ; Thu, 08 Mar 2012 21:58:05 -0500 Received: by qcmt36 with SMTP id t36so916162qcm.29 for ; Thu, 08 Mar 2012 18:58:02 -0800 (PST) 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 :content-type:content-transfer-encoding; bh=HtpgiIXY2OGQOCIQ2/Nnw7q6gptJ3QNr0T4c3fOtmWM=; b=vRBZk6H1xdJnTAo+OhmRP15ihuVfcmL9l0t+7SGRfPFiiWqqUANptpCFzI7rQgL4fT g7c3iFZXlETsCSnSD8S1U2w6VtnwTR9IG2ZXcHdVSbIidztYA79fyckL4c95GHh4FZbA mi8rsieYcUs8UyT0yuEkLEp9CoJBijHhl8S1ezZk97bLRp/M7TNRNvoe0TC80blQfgqW VP+TdngKir8agOBXWqzoUWSZXoQpGkVurx0oATyqk3iGrdit9l/QSAqxPB4ejs+tjAas mTlbHNP5V9CjaVr/ZVB9jOjh/f0VwarpynjtOn5q9RVLO+UD1sC2UMUnMtOnYW3q6nyh XeKQ== MIME-Version: 1.0 Received: by 10.224.32.12 with SMTP id a12mr245383qad.66.1331261881879; Thu, 08 Mar 2012 18:58:01 -0800 (PST) Received: by 10.229.49.74 with HTTP; Thu, 8 Mar 2012 18:58:01 -0800 (PST) In-Reply-To: References: Date: Thu, 8 Mar 2012 21:58:01 -0500 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters From: ircmaxell@gmail.com (Anthony Ferrara) Actually, it turns out the segfault and auto-reference bugs were easier than I thought to fix. I've updated both gists with the new code, and it looks to be running quite well... On Thu, Mar 8, 2012 at 9:32 PM, Anthony Ferrara wrote= : > Hey all, > > As promised, I've created a POC patch to implement scalar type hints, > the way that zend_parse_parameters handles hinting. =A0First off, here's > the patch: > > Directly apply-able without re2c: > https://gist.github.com/2004623 > > Removing generated files (requires re2c to compile): > https://gist.github.com/2004650 > > > It's a POC, but it mostly works. =A0There is one known issue: passing a > class implementing __toString to a string hinted function will raise a > segmentation fault. =A0There's also an issue of not separating the > argument on cast yielding to reference whether indicated or not, but > that should be easy to fix (it's just issuing a SEPARATE_IF_NOT_REF in > the cases where it would cast)... I'll work on cleaning it up, but I > wanted to show the concept before investing too much work... > > So, basically, there are 4 new parameters: > > bool > int > float > string > > The casting vs error rules are identical to zend_parse_parameters. =A0So: > > function fooi(int $i) { var_dump($i); } > > fooi(1); // int(1) > fooi(1.5); // int(1) > fooi("1"); // int(1) > fooi("1abc"); // int(1) + notice about non-well-formed numeric > fooi("foo"); // E_RECOVERABLE_ERROR > fooi(true); // int(1) > fooi(array()); // E_RECOVERABLE_ERROR > fooi($obj); // E_RECOVERABLE_ERROR > > function foob(bool $b) { var_dump($b); } > > foob(1); // bool(true) > foob(1.5); // bool(true) > foob("1"); // bool(true) > foob("abc"); // bool(true) > foob(true); // bool(true) > foob(array()); // E_RECOVERABLE_ERROR > foob($obj); // E_RECOVERABLE_ERROR > > function foos(string $s) { var_dump($s); > foos(1); // string("1") > foos(1.5); // string("1.5") > foos("1"); // string("1") > foos(true); // string("1") > foos(array()); // E_RECOVERABLE_ERROR > foos(new StdClass); // E_RECOVERABLE_ERROR > foos($objImpl__toStringORcast_object); // string(result) > > Float works like int, so I won't list it out here... > > > > So, what do you think? > > Thanks, > > Anthony