Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48401 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83212 invoked from network); 23 May 2010 04:43:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 May 2010 04:43:56 -0000 Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.185 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 212.25.124.185 il-mr1.zend.com Received: from [212.25.124.185] ([212.25.124.185:37225] helo=il-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/13-54147-A82B8FB4 for ; Sun, 23 May 2010 00:43:55 -0400 Received: from il-gw1.zend.com (unknown [10.1.1.21]) by il-mr1.zend.com (Postfix) with ESMTP id 97156504F4; Sun, 23 May 2010 07:20:57 +0300 (IDT) Received: from LAP-ZEEV.zend.com ([10.1.20.36]) by il-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Sun, 23 May 2010 07:43:51 +0300 Message-ID: <7.0.1.0.2.20100523073125.0a601600@zend.com> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Sun, 23 May 2010 07:43:50 +0300 To: Hannes Magnusson Cc: Lukas Kahwe Smith ,Josh Davis , internals@lists.php.net In-Reply-To: References: <7.0.1.0.2.20100522175819.0a601c68@zend.com> <93EFAEF4-26F3-44A1-85ED-5E71E665B966@pooteeweet.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-OriginalArrivalTime: 23 May 2010 04:43:51.0349 (UTC) FILETIME=[8A901E50:01CAFA32] Subject: Re: [PHP-DEV] Type hinting From: zeev@zend.com (Zeev Suraski) At 01:01 23/05/2010, Hannes Magnusson wrote: >On Sat, May 22, 2010 at 22:39, Lukas Kahwe Smith wrote: > > > > On 22.05.2010, at 18:30, Josh Davis wrote: > > > >> As you wrote, you worked on PHP's _type system_ which is dynamic, > >> really cool, juggles strings with ints and what not. However, the > >> topic here is the _type hinting system_. As far as I know, there's no > >> "weak" type hinting; if a method signature hints for an array and is > >> given an integer, it throws a catchable fatal error. Therefore, as a > >> user, what I am familiar to is a strict _type hinting system_. > >> Anything else would feel inconsistent to me. > > >I agree. function foo(array $x) {} foo(123); doesn't cast int(123) to >array(123) so introducing different meaning for scalar types feels >very very wrong. You're ignoring one simple fact - in PHP, scalar types are interchangeable. Unlike array->scalar which has always been a corner case and a sketchy one (and I said numerous times that had I rewrote the language now, array->scalar conversion would have probably resulted in an error) - string->number, number->string, string->boolean conversions are a cornerstone of the language. If you don't like the fact that PHP's scalar types are interchangeable - you're in the wrong language! In terms of consistency, the difference between array type hinting and scalar type hinting you allude to is negligible in comparison to the inconsistency with, well, just about every other part of the language - operators, control structures and built-in functions (expecting sqrt("64") to fail, since sqrt() expects a number? expecting if (7) to fail, since it expects a boolean?). Auto-converting type hinting extends the same semantics available to internal functions (through zend_parse_parameters()) to userland functions. That consistency is by far the most important IMHO. Zeev