Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44886 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84214 invoked from network); 10 Jul 2009 00:28:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jul 2009 00:28:40 -0000 X-Host-Fingerprint: 99.189.103.1 99-189-103-1.lightspeed.tulsok.sbcglobal.net Received: from [99.189.103.1] ([99.189.103.1:10470] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/80-30297-63B865A4 for ; Thu, 09 Jul 2009 20:28:39 -0400 To: internals@lists.php.net,troels knak-nielsen Message-ID: <4A568B33.9000501@gmail.com> Date: Thu, 09 Jul 2009 19:28:35 -0500 User-Agent: Thunderbird 2.0.0.18 (Windows/20081105) MIME-Version: 1.0 References: <7.0.1.0.2.20090708224156.0ac5a438@zend.com> <312025EF-84D0-4411-A0A7-4F0379C3105F@pooteeweet.org> <22CAD497EA2F476DAECEF9302D0B087A@pc> <98b8086f0907091150r47e7a103jaa50fcf7d5b32186@mail.gmail.com> In-Reply-To: <98b8086f0907091150r47e7a103jaa50fcf7d5b32186@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 090709-0, 07/09/2009), Outbound message X-Antivirus-Status: Clean X-Posted-By: 99.189.103.1 Subject: Re: [PHP-DEV] Type hinting - Request for Discussion From: spam.goes.in.here@gmail.com (Josh Thompson) troels knak-nielsen wrote: > 1) It covers all the use cases for a type-based system (You can use > `is_integer` as a contract, if you want that) > 2) It's extensible in user-space, which means that it can be used to > convey much more accurate information, relevant to the application > needs. > 3) It's focused on the interface of input-parameters, rather than their type. This is my favorite alternative so far. There are just a few problems with parsing as I see it. - How do you know if it is a contract or the current object type hint? - It doesn't allow a type to be forced (casted) to the correct type. To address these items, I suggest the following changes. Change the syntax of the contract to look like a function call (which is essentially what we are doing): $val) { if (!is_numeric($val)) { return false; } $x[$key] = (float)$val; } return true; } function sum(array_of_float($a)) { return array_sum($a); } -- Joshua Thompson Mechanical Engineer/Software Developer http://www.schmalls.com