Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34382 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4893 invoked by uid 1010); 4 Jan 2008 00:42:57 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4878 invoked from network); 4 Jan 2008 00:42:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2008 00:42:57 -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:61392] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/D8-20810-1118D774 for ; Thu, 03 Jan 2008 19:42:57 -0500 Received: from addw by mint.phcomp.co.uk with local (Exim 4.67) (envelope-from ) id 1JAaeC-0000X0-7E; Fri, 04 Jan 2008 00:42:52 +0000 Date: Fri, 4 Jan 2008 00:42:52 +0000 To: Markus Fischer Cc: Alain Williams , Sam Barrow , Tomi Kaistila , internals@lists.php.net Message-ID: <20080104004252.GW7861@mint.phcomp.co.uk> References: <200801031903.01980.tomi@cumulo.fi> <1199380881.15292.11.camel@sbarrow-desktop> <20080103172813.GQ7861@mint.phcomp.co.uk> <477D2B40.9010302@fischer.name> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <477D2B40.9010302@fischer.name> User-Agent: Mutt/1.4.1i Organization: Parliament Hill Computers Ltd Subject: Re: [PHP-DEV] RE: Optional scalar type hinting From: addw@phcomp.co.uk (Alain Williams) On Thu, Jan 03, 2008 at 07:36:48PM +0100, Markus Fischer wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello, > > Alain Williams wrote: > > On Thu, Jan 03, 2008 at 12:21:21PM -0500, Sam Barrow wrote: > >> I think E_WARNING would be appropriate. That's what happens when you > >> omit an argument to a function right? > > > > The other thing to note about type hinting is that it could result in faster code. > > The value is checked and if needed converted (eg string -> integer) when the > > function is called; it then need not be converted again when it is used in > > the function. This will presumably be a win if the value is used more than once. > > I don't think that automagic conversion of types is a good idea. > > When the type hint says I want an integer, then only integer should be > accepted; no casting should be done. It may give predictable results Maybe the type checks should be stricter than normal. What are we going to want here ? * integer - possibly convert from: - string, in which case we just accept digits with an option + or - The important thing is that the *entire* string must convert - float - the standard truncate towards zero Nothing else * float - possibly convert from: - integers - standard convertion - string - accept a float in the standard formats The important thing is that the *entire* string must convert * boolean. At first glance this is easier as the convert to boolean for lots of types is well defined. In most cases the programmer would not be interested in a type check, so if he specifies it then we should be very restrictive. * string - possibly convert from: - integers & float - standard convertion - boolean - standard convertion - objects - only if they have a __toString() method -- 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