Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33161 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83513 invoked by uid 1010); 15 Nov 2007 16:35:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 83498 invoked from network); 15 Nov 2007 16:35:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Nov 2007 16:35:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=jeremy@omegavortex.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jeremy@omegavortex.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain omegavortex.net from 207.210.105.50 cause and error) X-PHP-List-Original-Sender: jeremy@omegavortex.net X-Host-Fingerprint: 207.210.105.50 analucia.asmallorange.com Received: from [207.210.105.50] ([207.210.105.50:43946] helo=analucia.asmallorange.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/F5-63493-5457C374 for ; Thu, 15 Nov 2007 11:35:17 -0500 Received: from [24.8.172.240] (port=2117 helo=[192.168.15.104]) by analucia.asmallorange.com with esmtpa (Exim 4.68) (envelope-from ) id 1IshgD-0005TJ-3R; Thu, 15 Nov 2007 11:35:01 -0500 Message-ID: <473C752F.3010803@omegavortex.net> Date: Thu, 15 Nov 2007 09:34:55 -0700 Organization: Omega Vortex Corporation User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: RQuadling@GoogleMail.com CC: Sam Barrow , internals@lists.php.net References: <1195140437.23612.5.camel@sbarrow-desktop> <10845a340711150806i186e6363k9c1fcae62c862f12@mail.gmail.com> In-Reply-To: <10845a340711150806i186e6363k9c1fcae62c862f12@mail.gmail.com> Content-Type: multipart/alternative; boundary="------------080201060205000004060307" X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - analucia.asmallorange.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - omegavortex.net X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] [PATCH] Optional scalar type hinting From: jeremy@omegavortex.net (Jeremy Privett) --------------080201060205000004060307 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Richard Quadling wrote: > On 15/11/2007, Sam Barrow wrote: > >> I found a patch by Derick online to allow for scalar type hinting, and >> made it work with the newest snapshot of PHP 5.3. I also added the >> ability to type hint for resources. I would like to ask that it be added >> to the next PHP release. It allows type hinting for int, float, bool, >> string, resource, and object, I also added the ability to use the >> secondary keywords for all of these types (such as double, real, long, >> etc.). >> >> It will maintain 100% backwards compatibility, as the type hinting is >> 100% optional, implemented in the same way as array/class type hinting. >> >> I have the patch on my PC, please let me know where and when i can >> submit it. I'd be happy to do the patching and submission myself, just >> asking for permission here. >> > > What happens for type conversion? Is the param cast to the hinted type? > > The idea of type hinting for array and class is to make sure you get > something appropriate. > > Rarely would you think of an array and cast it as an integer (or vice > versa), so it makes sense. > > But with a string ("0"), an integer (0) or a boolean (false), they are > all the same, so does this mean we would be having to cast all the > params to the function/method? > I imagine that it will behave the same was as the other type hinting and just bomb out if the incoming data is of the wrong type. It kind of defeats the purpose of type "hinting" if it's really just type "casting" in the method call. To your point, I think it would really only help those OCD developers among us who always use === and try to make PHP behave like a strongly typed language. --- Jeremy Privett C.E.O. & C.S.A. Omega Vortex Corporation --------------080201060205000004060307--