Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34429 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56154 invoked by uid 1010); 4 Jan 2008 17:51:49 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56139 invoked from network); 4 Jan 2008 17:51:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2008 17:51:49 -0000 Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 213.152.38.186 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 213.152.38.186 freshmint.phcomp.co.uk Linux 2.5 (sometimes 2.4) (4) Received: from [213.152.38.186] ([213.152.38.186:61229] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/60-63281-4327E774 for ; Fri, 04 Jan 2008 12:51:48 -0500 Received: from addw by mint.phcomp.co.uk with local (Exim 4.67) (envelope-from ) id 1JAqhp-0003YZ-5R; Fri, 04 Jan 2008 17:51:41 +0000 Date: Fri, 4 Jan 2008 17:51:41 +0000 To: Robert Cummings Cc: Pierre , Marcus Boerger , Gregory Beaver , Alain Williams , internals Mailing List Message-ID: <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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1199468241.6629.53.camel@blobule> User-Agent: Mutt/1.4.1i Organization: Parliament Hill Computers Ltd Subject: Re: [PHP-DEV] type hinting From: addw@phcomp.co.uk (Alain Williams) 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'. > ?> > > 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