Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34431 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61472 invoked by uid 1010); 4 Jan 2008 17:55:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 61457 invoked from network); 4 Jan 2008 17:55:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2008 17:55:06 -0000 Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sambarrow.com from 205.234.132.11 cause and error) X-PHP-List-Original-Sender: sam@sambarrow.com X-Host-Fingerprint: 205.234.132.11 scottsdale.servershost.net Received: from [205.234.132.11] ([205.234.132.11:40967] helo=scottsdale.servershost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/81-63281-AF27E774 for ; Fri, 04 Jan 2008 12:55:06 -0500 Received: from [98.172.154.66] (port=30133 helo=[10.200.100.14]) by scottsdale.servershost.net with esmtpsa (SSLv3:RC4-MD5:128) (Exim 4.68) (envelope-from ) id 1JAql2-0006lv-5b; Fri, 04 Jan 2008 11:55:00 -0600 To: Alain Williams Cc: Robert Cummings , Pierre , Marcus Boerger , Gregory Beaver , internals Mailing List In-Reply-To: <20080104175141.GC12202@mint.phcomp.co.uk> References: <477DB7BF.10201@chiaraquartet.net> <20080104105558.GC7861@mint.phcomp.co.uk> <477E5649.2080104@chiaraquartet.net> <1463438959.20080104182050@marcus-boerger.de> <1199468241.6629.53.camel@blobule> <20080104175141.GC12202@mint.phcomp.co.uk> Content-Type: text/plain Date: Fri, 04 Jan 2008 12:53:26 -0500 Message-ID: <1199469206.15292.164.camel@sbarrow-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - scottsdale.servershost.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sambarrow.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] type hinting From: sam@sambarrow.com (Sam Barrow) On Fri, 2008-01-04 at 17:51 +0000, Alain Williams wrote: > On Fri, Jan 04, 2008 at 12:37:19PM -0500, Robert Cummings wrote: > > > IMHO, optionally inclusion of type hinting for functions/methods can > > only be a boon to code quality and readability. IMHO when a type hint is > > provided and a parameter doesn't match the type hint then I think a > > fatal error should occur. This forces the user of the function that has > > type hinting to ensure their data is of the correct type. This prevents > > accidental wrong data conversion. However, I see the other side of the > > coin too where automatic type conversion could be desirable also. > > Perhaps a mixed solution would be viable? > > > > > > > function foo( require int $a, require string $b ){} > > > > foo( '5', 'bleh' ); // <-- fatal error > > No. > > > ?> > > > > Contrast versus: > > > > > > > function foo( int $a, string $b ){} > > > > foo( '5', 'bleh' ); // <-- no exception or error $a in foo() will > > // be type int (automatic conversion) > > Yes. If $a is '5' but reject if $a is '5five'. This is what I was considering, but to do something like this we will have to implement a whole separate rule set just for type hint conversion. > > ?> > > > > Versus (still allowed default style): > > > > > > > function foo( $a, $b ){} > > > > foo( '5', 'bleh' ); // <-- no exceptions or type conversions > > > > ?> > > > > Thoughts? > > > > Cheers, > > Rob. > > -- > > ........................................................... > > SwarmBuy.com - http://www.swarmbuy.com > > > > Leveraging the buying power of the masses! > > ........................................................... > > -- > Alain Williams > Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. > +44 (0) 787 668 0256 http://www.phcomp.co.uk/ > Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php > Chairman of UKUUG: http://www.ukuug.org/ > #include >