Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44887 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86541 invoked from network); 10 Jul 2009 00:44:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jul 2009 00:44:56 -0000 Authentication-Results: pb1.pair.com header.from=troelskn@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=troelskn@gmail.com; spf=pass; sender-id=pass 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:46391] helo=mail-bw0-f206.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/E0-30297-70F865A4 for ; Thu, 09 Jul 2009 20:44:56 -0400 Received: by bwz2 with SMTP id 2so531094bwz.23 for ; Thu, 09 Jul 2009 17:44:53 -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=hbq6OleelsSzQ+17BqmnNWOZqQv/POc7XliwCtsOaoE=; b=mV+E+OG5U+jX/Ih3zFcDbNelGMZFSrEcISQC9hJIsRsLVvpHXHBzWtx6Y/3xKEkUDV xahVcetiYSWSdLuaJfGd7dkc9u2fpp7oGrOLly6t46ZYxlxQy7M0BqljUJoQ0ckS9sjR 0oufyfm+9Mzj4w/5BBjcZ8d/B7DvMtBVTbwEk= 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=ioNNtMnNRyoN5oAH1VxV4rHdDSKq5MWXWCSlyrsKoTO/fUfh9JTZ7g5TjO7/WEz1dS uZ0rNbBmq5dD4CM35eqqVuxEM/XKYwUF+sHRWWiTzaXd3zVcqgi2YnYezclrulXi2jp1 UcvOCVSy/6E2oGGrj5tFx7TSYc3zZykLuLXjo= MIME-Version: 1.0 Received: by 10.223.108.75 with SMTP id e11mr658270fap.51.1247186692929; Thu, 09 Jul 2009 17:44:52 -0700 (PDT) In-Reply-To: <4A568B33.9000501@gmail.com> References: <7.0.1.0.2.20090708224156.0ac5a438@zend.com> <312025EF-84D0-4411-A0A7-4F0379C3105F@pooteeweet.org> <22CAD497EA2F476DAECEF9302D0B087A@pc> <98b8086f0907091150r47e7a103jaa50fcf7d5b32186@mail.gmail.com> <4A568B33.9000501@gmail.com> Date: Fri, 10 Jul 2009 02:44:52 +0200 Message-ID: <98b8086f0907091744w7ab598dckc427d0a9484664b2@mail.gmail.com> To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Type hinting - Request for Discussion From: troelskn@gmail.com (troels knak-nielsen) On Fri, Jul 10, 2009 at 2:28 AM, Josh Thompson wrote: > troels knak-nielsen wrote: > =A0- How do you know if it is a contract or the current object type hint? The simplest solution would be to make one take precedence. You're not likely to have both a class and a function with the same name, and if you do, you kind of had it coming to you. For backwards compatibility it would probably be most fitting to let the current behaviour (class/interface) take precedence, although the other way around makes for some quite interesting possibilities. > =A0- It doesn't allow a type to be forced (casted) to the correct type. As far as I can tell, this is a moot point. The whole discussion about casting comes from the fact that hinting to a primitive type is more restrictive than php's weak typing system. With a contract system this problem doesn't exist. You could test that something conforms to your specifications and then simply let the type system do its thing. For example, instead of: function addFive(int $x) { return $x + 5; } You would simply do: function addFive(is_numeric $x) { return $x + 5; } Since $x is guaranteed to be numeric, it is safe to to arithmetic on it. No reason to explicitly type cast here. -- troels