Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44611 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76040 invoked from network); 1 Jul 2009 21:37:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jul 2009 21:37:09 -0000 Authentication-Results: pb1.pair.com header.from=paul.biggar@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=paul.biggar@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.227 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: paul.biggar@gmail.com X-Host-Fingerprint: 209.85.219.227 mail-ew0-f227.google.com Received: from [209.85.219.227] ([209.85.219.227:47323] helo=mail-ew0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/E6-43450-407DB4A4 for ; Wed, 01 Jul 2009 17:37:09 -0400 Received: by ewy27 with SMTP id 27so1381557ewy.23 for ; Wed, 01 Jul 2009 14:37:06 -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 :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=qgpseynzaMHIpMxzLpJ1/QBSu/XxjZl3iPsAeoxCMMM=; b=tyswPIeoDBZJ8H2MYUKaxt0NMsclgkdsUWx1Dzl1wBMsuCPwv0qZW50Fw7Izzcaqvh C50Ql/xyHK+OiNtMULLY6SIJCy/ItSTjalcr9VgkxKKFvMqH9pP1ESNY6fPgbKYoFgws EEqUV90N5NaDEi9f/3JprN8fHdb6sUhspHYOk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=cWt1pzverumYv9uN/m2ZAPzddO5/B1deZiefjpYImiQwGwto9UsTea3DzYbgTm2tDu W+6twNbIXBjpbLPlTKgFXYVGF+oqTjhH+n1tHegkBrorGj4mom5S7yT/UjX7/dIYMKdw t7vzESRQ4UGdqeO3Me691e3uNkGII1aWEzhaM= MIME-Version: 1.0 Received: by 10.210.79.3 with SMTP id c3mr476601ebb.16.1246484226355; Wed, 01 Jul 2009 14:37:06 -0700 (PDT) In-Reply-To: <7f3ed2c30907011423p28e693c1nc4da1e2b20ca8a45@mail.gmail.com> References: <4A4BAE7B.3020601@zend.com> <39D0B97E-3A70-44E3-B1BC-D68A0E58CA76@prohost.org> <4A4BC731.1020909@zend.com> <7f3ed2c30907011342y24ccd2c7te5f7c273f001fa7a@mail.gmail.com> <4A4BCC0D.6000704@zend.com> <7f3ed2c30907011402taa51848h56dfff924c59a6cb@mail.gmail.com> <7f3ed2c30907011423p28e693c1nc4da1e2b20ca8a45@mail.gmail.com> Date: Wed, 1 Jul 2009 22:36:46 +0100 Message-ID: To: Hannes Magnusson Cc: Stanislav Malyshev , Ilia Alshanetsky , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Type hinting revisited for PHP 5.3 From: paul.biggar@gmail.com (Paul Biggar) On Wed, Jul 1, 2009 at 10:23 PM, Hannes Magnusson wrote: > On Wed, Jul 1, 2009 at 23:07, Paul Biggar wrote: >> So, what you're saying is, the patch already handles coercion? If >> that's the case, then problem solved. > > The patch offers scalar type _hinting_. Not type _casting_. > > Type hinting in PHP works very simply: If the value doesn't type-match > the argument information (arginfo internally) then it will be rejected > and E_RECOVERABLE_ERROR thrown. > > In most circumstances that error is fatal. However. If the user > chooses then he can ignore that error (by creating his own error > handler) and continue the execution. > > Type _hinting_ is in no way related to type _casting_. It should be. The current type hinting is for objects, which in PHP are strongly typed. We plan to extend it to scalars, which in PHP are weakly typed. Adding a strong type system for scalars goes against the rest of the language. As Stas said: > With this patch, we won't have one logic anymore - we'd have two logics - one for typehinted functions (reject everything that doesn't match the type) and one for the rest of the language (try to coerce > types). Two logics in one language is usually not good. PHP already has 2 type systems. I don't think that adding a 3rd one is complementary. > Furthermore, the patch introduces couple of new types, "scalar" and > "numeric". These are "magic types" and do value-to-real-type > comparison. No type casting. > The scalar type hint accepts strings, booleans, ints and floats. > The numeric type hint accepts strings (that pass is_numeric()), > booleans, ints and floats. Yes. Therefore only the scalar and numeric types are useful. Nobody wants to use an 'int' hint that fails on numeric strings. Also, I don't know what happens for string hints when you pass an object with a __toString handler, but it should be allowed. Thanks, Paul -- Paul Biggar paul.biggar@gmail.com