Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34610 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67696 invoked by uid 1010); 8 Jan 2008 21:24:55 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 67671 invoked from network); 8 Jan 2008 21:24:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jan 2008 21:24:55 -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:55416] helo=scottsdale.servershost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/FF-38195-42AE3874 for ; Tue, 08 Jan 2008 16:24:54 -0500 Received: from [98.172.154.66] (port=48967 helo=[10.200.100.14]) by scottsdale.servershost.net with esmtpsa (SSLv3:RC4-MD5:128) (Exim 4.68) (envelope-from ) id 1JCLwJ-0007lt-NL; Tue, 08 Jan 2008 15:24:51 -0600 To: Tomi Kaistila Cc: internals@lists.php.net In-Reply-To: <200801082247.51805.tomi@cumulo.fi> References: <200801081603.35826.tomi@cumulo.fi> <1199803721.15292.269.camel@sbarrow-desktop> <200801082247.51805.tomi@cumulo.fi> Content-Type: text/plain Date: Tue, 08 Jan 2008 16:22:45 -0500 Message-ID: <1199827365.15292.289.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 Tue, 2008-01-08 at 22:47 +0200, Tomi Kaistila wrote: > > But the syntax is longer ("$a = 5" vs "$a = new Integer(5)"), and if you > > have a large application with hundreds of integers it starts to add up. > > Performance is also much worse when using objects for every variable. > I agree. That is what I meant by "ugly" and "clumsy" in my last post. > > > > This sounds like, at least, a partial victory to adding proper type > > > hinting to PHP but in my mind it is not enough. I have counted that about > > > a quarter of all type hints that I would make is about matching the > > > argument's type to scalar. The rest are about separating specific scalars > > > from each other. In most cases integer and boolean. > > > > Better than nothing. > No, it is not. It is actually better to not fix it at all, if you cannot fix > it properly. Especially in this case when the feature has already once been > left "unfinished". > > The benefit is zero for me, if when I need to hint a boolean and can only hint > a scalar. In that case, I will still have to do the validating myself. I > might as well leave the type hinting out all together, instead of waste > resources for having first PHP check that it is a scalar and then my own code > to check that it is a boolean. > > Actually, if I can only hint "scalar" in general, I am essentially telling the > users of my API that they should be ready for two types of errors. That which > occurs when the argument is not a scalar and that which occurs when it is not > a boolean. One will be a PHP error and the second will be an exception. Would > be easier on them if I do not use type hinting at all in that case. Ok, but a scalar becomes useful for a couple of important things. Scalars are all displayable values, that can be stored in a db, outputted, etc. The scalar type hint prevents errors related to objects, resources, and arrays attempting to be stored in the db or echoed. > I say, do it properly or do not do it at all. > > Tomi Kaistila > PHP Developer >