Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58803 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31360 invoked from network); 9 Mar 2012 02:58:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2012 02:58:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=ilia@prohost.org; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ilia@prohost.org; sender-id=pass Received-SPF: pass (pb1.pair.com: domain prohost.org designates 74.125.83.42 as permitted sender) X-PHP-List-Original-Sender: ilia@prohost.org X-Host-Fingerprint: 74.125.83.42 mail-ee0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:65258] helo=mail-ee0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/B3-10820-EE1795F4 for ; Thu, 08 Mar 2012 21:58:55 -0500 Received: by eekb57 with SMTP id b57so318476eek.29 for ; Thu, 08 Mar 2012 18:58:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding:x-gm-message-state; bh=m791OTM3Oh8rWc73avxT4mLaf1Bp4BaGfZ7RJHsijBU=; b=Rf7wKGP2hVG3QSwchtrSvb/ol/Xhm1nzBfiK6xCOs+qeXBU/LI7yxS8UqI6Zf8rTEN +BrLCxZSQU9NM9FMOiZpS55VJSyyzwPoZSIFBjSzu20w0Zrs2nvkJ4uBgv/ggTKQQKZO pYqXQojfRjExyXI8ULVO+u5JCm9dzW7lNb3gw31pZxe8JHZqsaZKH26MqhzlJmzs8jXf sjLcDU+H1aQy1HHBDokQ5JqEkHTGQ0VtKhFV3u8uMtk8zNNk221n02pR5LrZFDpu4bIB ZJM/80rqx8kRHu7GioWWKouoJeuiqH9YsmPTtzqmDckVLchs6XYbaylLKyEpTL2I8RIL 9Znw== MIME-Version: 1.0 Received: by 10.14.33.204 with SMTP id q52mr103337eea.11.1331261932120; Thu, 08 Mar 2012 18:58:52 -0800 (PST) Received: by 10.14.99.70 with HTTP; Thu, 8 Mar 2012 18:58:52 -0800 (PST) In-Reply-To: References: Date: Thu, 8 Mar 2012 21:58:52 -0500 Message-ID: To: Anthony Ferrara Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQkEloYZ8l9KifWquT9UEnakzBDQ8A1/clagnZIUxyAsEUzFtQRV+Q2G7IAflyGl+Zj7WEOo Subject: Re: [PHP-DEV] [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters From: ilia@prohost.org (Ilia Alshanetsky) Anthony, My concern with this type of patch is that what you are proposing are not really hints, they are forced casts. As such they modify the data potentially leading to data loss. 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >