Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58743 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99575 invoked from network); 7 Mar 2012 15:05:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2012 15:05:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=arvids.godjuks@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=arvids.godjuks@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: arvids.godjuks@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:47138] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/13-15180-B19775F4 for ; Wed, 07 Mar 2012 10:05:00 -0500 Received: by werh12 with SMTP id h12so4596275wer.29 for ; Wed, 07 Mar 2012 07:04:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=f10dmWr+YyuDAqPkKcM8ZTrgstsFZDlYLDs6+iE9RKM=; b=ZjN7joz+FvYF3T8THZy+/e5Uk6rZzVmdMsVtbel7FismoXYd1xFG+cXRylDtMk45z7 GhKMIwP6WnNRTJ55uYBrwvzAPfcZH4DabMhE3DcUJFPi0ZiJOtvsI2PNWdR2AFp1BkcJ BoeFZpvVJ5o4of62M4IsxAQ8ptTaf+Vr4LSVYs5roiziej2YCuozBviRgxowhj64HbuO BxltnQ0PQUQH91JBxpaJ3W6GhVaNuWoNHkHMm+cefGlKwYc1Qksg19KXXgMxyr/Yq6g2 DPAP9ajms10iHQ1ZXULnMg7NnRwuszpucc3rOwQARd4SP1kP4+yq1Xk+wYhzxepCBT3c IcJA== Received: by 10.180.93.4 with SMTP id cq4mr4523673wib.21.1331132697139; Wed, 07 Mar 2012 07:04:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.117.1 with HTTP; Wed, 7 Mar 2012 07:04:37 -0800 (PST) In-Reply-To: References: <52.38.15021.3A1E65F4@pb1.pair.com> <4F570EBB.6030103@sugarcrm.com> <60744d7ea642fe03c7110502a3f4276a@mohiva.com> Date: Wed, 7 Mar 2012 17:04:37 +0200 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Scalar Type Hinting From: arvids.godjuks@gmail.com (Arvids Godjuks) I, for one, decided not to participate in the discussions any more because they always change to something different in a few hours of discussion. I'm surprised how people tend to complicate the feature into something weird and ugly. I now understand why core team just ignores some discussions. I don't like the function a( (int) $int) syntax and approach - it's not type hinting, it's auto-converting arguments. And adding function a( (array) $array) is just, well, pointless. Why? Because if you have a conversion from scalar to array - you definitely have something wrong in the code that needs fixing, not converting and continue to run the code like it's OK. It should come like a barrier, not a filter. And current array and object type hinting does just that. The (object) is also pointless for type hinting. Why? Because you usually expect not any damn object, but an object of certain type and it's children. That works now just fine and errors the hell out if something isn't right. I realize that with scalars it's not that straight forward, but complicating things by adding an auto-cast syntax and so on is just ridiculous. Hints should stay, well, hints. The only problem we have is complications of accepting numerical strings or numbers as strings. And what to do with "null". Everything else is irrelevant. function a(bool $bool) {} a(10); // Kill your self against the wall - write a(true); If you define bool - use the damn bool! It's not an "if" or "switch" statement where auto-converting is usually used. It's a function call, you should pass to it correct arguments. Type hinting is working only for more internal API's - the data filtering and validating layer using type hints will generate errors all over the place. We all know how many security hole scanners out there that scan sites and pass all kind of data to our scripts to break them and try exploiting that. I consider interchangeable only three cases: 1. Numerical string. 2. Integers and floats as strings. 3. Integer and string 0 1 as bool. Any other cases should error out. Type hinting is not for using it all over the place - it should be used in places it is really needed. And it should define the expected type with some auto-converting limited special cases like I have written above. That is really all it needs. No super-duper-auto-converting type-hints, no variable type hinting and other wild stuff I have seen during last 2-3 weeks. Anything more complicated than that and count a -1 vote from me.