Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44878 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99663 invoked from network); 9 Jul 2009 18:50:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jul 2009 18:50:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=troelskn@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=troelskn@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.206 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: troelskn@gmail.com X-Host-Fingerprint: 209.85.218.206 mail-bw0-f206.google.com Received: from [209.85.218.206] ([209.85.218.206:64350] helo=mail-bw0-f206.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/1F-30297-2EB365A4 for ; Thu, 09 Jul 2009 14:50:11 -0400 Received: by bwz2 with SMTP id 2so373481bwz.23 for ; Thu, 09 Jul 2009 11:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=cTKMXcMlxhwYLBa1UMUIokaeIDZNVg/uzc7Jks/CAo4=; b=lXJ/seVpJX04AgroDl6xkzEADzyz26LRGEwcu8md1AOElQGfNPkg3AtvyFxPRrEoCi ffl+haQc1wCik0lWaklwMAhvbprOaWNSBfDswrZKaefc9yGWeWTvFEF0WDsYA1nu0Pb2 dXd/gIwyZpLeSCqFAhmaglHcjzbEGJTHt+kBs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=AM8BKnlrYVaBa0Y8ujyjgN98AlDJeIgux4sc3hBKJTiru06twr/hZtRqxHH303CeVz h2kGfOX/+8t77c+TQLBRzHmb1tZ6jYB30ztzwpWmOY2CtpV7rdlFZOmVc+rqjKrkzNrB mxtih4cEAnzJA4zyVDE9jjdyJeL8+mZ8+6/5s= MIME-Version: 1.0 Received: by 10.223.126.1 with SMTP id a1mr536544fas.52.1247165407261; Thu, 09 Jul 2009 11:50:07 -0700 (PDT) In-Reply-To: <22CAD497EA2F476DAECEF9302D0B087A@pc> References: <7.0.1.0.2.20090708224156.0ac5a438@zend.com> <312025EF-84D0-4411-A0A7-4F0379C3105F@pooteeweet.org> <22CAD497EA2F476DAECEF9302D0B087A@pc> Date: Thu, 9 Jul 2009 20:50:07 +0200 Message-ID: <98b8086f0907091150r47e7a103jaa50fcf7d5b32186@mail.gmail.com> To: PHP Developers Mailing List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Type hinting - Request for Discussion From: troelskn@gmail.com (troels knak-nielsen) Hi list. In advance, sorry for muddying the waters even further. Following the current discussion about typehints to primitives, I'm wondering if anyone have ever suggested to include some sort of user-land contract system, such as the one that exists in plt-scheme[1] Given the dynamic nature of php, I would suspect that it might be a much better fit. Unlike the semi-static typecheck that typehints can give, a contract system would be much more expressive and would add a lot more value (in my opinion anyway). I think part of the reason for the popularity of typehints is that it looks familiar for people coming from Java/C++/C#. The biggest challenge for such a contract system would then be to come up with something that doesn't look too alien. A simple way that I can think of is to overload the meaning of typehints so that they may either denote a class/interface (as they work currently) OR they may be a function which takes the variable as argument and yields a boolean. Eg.: function array_of_numeric($x) { foreach ($x as $val) { if (!is_numeric($val)) { return false; } } return true; } class Foo { /** Example use-case for a contract */ function sum(array_of_numeric $a) { return array_sum($a); } } This is just one suggestion - There are other ways to implement the concept. I can see a number of benefits to a contract system over the currently discussed typehint system: 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. [1] http://docs.plt-scheme.org/guide/contracts.html -- troels