Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34326 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88001 invoked by uid 1010); 3 Jan 2008 17:22:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 87986 invoked from network); 3 Jan 2008 17:22:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2008 17:22:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; 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:43017] helo=scottsdale.servershost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/52-20810-9E91D774 for ; Thu, 03 Jan 2008 12:22:50 -0500 Received: from [98.172.154.66] (port=55063 helo=[10.200.100.14]) by scottsdale.servershost.net with esmtpsa (SSLv3:RC4-MD5:128) (Exim 4.68) (envelope-from ) id 1JATmJ-0002k6-Bj; Thu, 03 Jan 2008 11:22:47 -0600 To: Tomi Kaistila Cc: internals@lists.php.net In-Reply-To: <200801031903.01980.tomi@cumulo.fi> References: <200801031903.01980.tomi@cumulo.fi> Content-Type: text/plain Date: Thu, 03 Jan 2008 12:21:21 -0500 Message-ID: <1199380881.15292.11.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] RE: Optional scalar type hinting From: sam@sambarrow.com (Sam Barrow) I think E_WARNING would be appropriate. That's what happens when you omit an argument to a function right? And about function return type hinting, I don't think it would be as useful as parameter type hinting, but it would be useful. Mostly for stuff like declaring an abstract function in a parent class that must return a certain type. class a { abstract public function getNumber() returns int ; } class b extends a { public function getNumber() { return rand() * 3463 ; } } class c extends a { public function getNumber() { return 'I\'m going to mess everything up by returning a string.' ; // Would cause error with type hinting. } } On Thu, 2008-01-03 at 19:03 +0200, Tomi Kaistila wrote: > Hello everyone > > I figured I would bring my opinion in to support of Sam's request for a more > complete type hinting feature. Namely I am interested in the support for > hinting scalar types on function and method arguments and I am sure it is > safe for me to say that I speak for a lot of people. Most people that I know > find the current type hinting, while useful, ridiculous because it looks like > the job was left unfinished for whatever abstract reason. > > In my opinion type hinting should definitely be allowed for scalar values. As > for return types, I am not so sure. So far I have found no use for such a > feature in my own code, so I won't comment on it. If it is added, I welcome > it for those who find it useful but if it is not added I will not loose sleep > over it. > > > I was thinking at something along the lines of objects also for instance: > > $i = new Integer(33); > After my own experiments with the subject I concur that while it can be made > to work, it is not only a bad idea (for the reasons mentioned earlier) it is > also redundant and just unnecessary. There is a lot better way to accomplish > the same and that by allowing scalar values to be hinted. It is simpler, > cleaner, and easier to implement. > > > What if type hinting just generated an E_NOTICE. Nothing more for the > > time being. > Changing it to E_NOTICE or E_STRICT defeats the purpose somewhat since if I > write a piece of code that hints that the argument for a-whatever method > needs to be an integer it seems useless if the user of my library can avoid > the issue just by supressing lesser errors and those who do not need to write > extensive error handling code to respond to this sort of error (if they > indeed deem it necessary to do so). > > While hinting is, and should remain, optional, when it is used it should be > enforced. After all the user of my library has the option to dump it and go > for another library that does not force types. That is the beauty of having > options. > > Tomi Kaistila > PHP Developer >