Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58814 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66884 invoked from network); 9 Mar 2012 09:50:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2012 09:50:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:63265] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/39-10820-062D95F4 for ; Fri, 09 Mar 2012 04:50:25 -0500 Received: by ghbg2 with SMTP id g2so851809ghb.29 for ; Fri, 09 Mar 2012 01:50:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=UJ/y4IslnRyYqjf43V/q4fyTgpfJ3L2YSdZV1H8quaU=; b=X4mMHSov0gsXDKOEYSyRUu6shcp2pYjScRKyyuDzXyoUIrU7z8VhUx2NoIAh/d7d1J HjlTCa3moo6Ue5pKbcjetPmBg745oygjEGPipbcki3KzuWSi1EgyxsAn1riQRsuLHGRk /MXxxdUEvupzqLkVxTIZSff+DE/AXlKwdIzT/jGMs5jmqbbmPwnv5bOizKmOyJmRIKjC 7KlmqNCauKWjfOv6tkM6zUEYAnjLDjpYMS4ZJ5lzrTAuwaYYbwt2hsg4Ij59OmlX7bN0 G2Co3uhm+QRtG3F+G+0IYahpUFZ6QAcm63tT3/YAKrM2Ix0Gi3fa0Smz8U4t4v30mQcK vAYQ== Received: by 10.236.177.6 with SMTP id c6mr1517649yhm.42.1331286621782; Fri, 09 Mar 2012 01:50:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.146.144.35 with HTTP; Fri, 9 Mar 2012 01:50:00 -0800 (PST) In-Reply-To: References: Date: Fri, 9 Mar 2012 10:50:00 +0100 Message-ID: To: Anthony Ferrara Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf305639012f81e804bacc52e9 Subject: Re: [PHP-DEV] [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters From: linepogl@gmail.com (Lazare Inepologlou) --20cf305639012f81e804bacc52e9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I like it. (Now, it would be nice to have another RFC about custom object casting to int, float and bool...) Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel 2012/3/9 Anthony Ferrara > Hey all, > > As promised, I've created a POC patch to implement scalar type hints, > the way that zend_parse_parameters handles hinting. First 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. There is one known issue: passing a > class implementing __toString to a string hinted function will raise a > segmentation fault. There'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. So: > > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf305639012f81e804bacc52e9--