Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49353 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54904 invoked from network); 11 Aug 2010 16:29:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2010 16:29:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:41316] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F7/E9-01618-FEFC26C4 for ; Wed, 11 Aug 2010 12:29:36 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 806B8700483A for ; Wed, 11 Aug 2010 17:29:32 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id HdrpkbCUTs3f for ; Wed, 11 Aug 2010 17:29:32 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 34A44700345D for ; Wed, 11 Aug 2010 17:29:32 +0100 (WEST) Received: from damnation.dulce.lo.geleia.net (52.152.108.93.rev.vodafone.pt [93.108.152.52]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 132012005429 for ; Wed, 11 Aug 2010 17:29:32 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <1281478269.6608.292.camel@guybrush> <4C61D6D0.90907@sugarcrm.com> <4C62B9E0.4030305@gmail.com> Date: Wed, 11 Aug 2010 17:29:21 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: User-Agent: Opera Mail/10.60 (Win32) Subject: Re: [PHP-DEV] Strict typing From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Wed, 11 Aug 2010 16:03:14 +0100, Alexey Zakhlestin wrote: > 2010/8/11 Ryan Panning : > >> Because the current syntax used for type hinting >> classes/arrays is strict. If changed, you would need to specify that >> scaler >> types are weak but classnames are strict and now you have a WTH moment. > > Not really. Class type-hinting is not strict. The only reason why it > looks strict is, that PHP doesn't provide userland ways for > object-casting. > As far as I remember, zend-engine, underneath, actually has hook for > casting. And nothing stops us from supporting such casting with hints, > eventually. > If you're referring to the cast_object handler, the only thing it can specify in terms of the target type is IS_STRING, IS_OBJECT, etc. I don't think what we have now and both strategies that are being considered are directly comparable, so the "the current type hinting* is/is not strict" and "the new strategy is/is not consistent with current type hinting" are just rhetoric. I'm my opinion, what we should strive for is consistency with the only comparable thing, the current parsing API, zend_parse_parameters. If an internal function says it accepts an array, it can only take an array**. If it says it only accepts an object of a certain type, it checks the inheritance hierarchy***. So the current type hinting implementation is already consistent with zend_parse_parameters. Unfortunately, both competing options want to deviate from this: - The strict side wants a simple, 'gettype' like check, that has nothing to do with the current API. - The weak side thinks the current parameter parsing API is a bit loose (for instance, if I'm not mistaken, all the scalars are automatically converted to bool), so it's better to create a whole new set of rules, even though they will still deviate slightly from the current API. In my opinion, the transition should be made slowly. First, by raising a warning on the undesirable automatic conversions we don't want, and finally disallowing them altogether and introducing a compatible user-space type hinting. * terminology objections aside ** the rare 'H'/'A', which also take an object, excluded) *** 'o' can also be given, which accepts all the object types -- Gustavo Lopes