Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58137 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71320 invoked from network); 27 Feb 2012 15:31:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 15:31:35 -0000 Authentication-Results: pb1.pair.com header.from=arvids.godjuks@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=arvids.godjuks@gmail.com; spf=pass; 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:38550] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/08-40985-6D1AB4F4 for ; Mon, 27 Feb 2012 10:31:35 -0500 Received: by werh12 with SMTP id h12so918343wer.29 for ; Mon, 27 Feb 2012 07:31:31 -0800 (PST) Received-SPF: pass (google.com: domain of arvids.godjuks@gmail.com designates 10.180.78.6 as permitted sender) client-ip=10.180.78.6; Authentication-Results: mr.google.com; spf=pass (google.com: domain of arvids.godjuks@gmail.com designates 10.180.78.6 as permitted sender) smtp.mail=arvids.godjuks@gmail.com; dkim=pass header.i=arvids.godjuks@gmail.com Received: from mr.google.com ([10.180.78.6]) by 10.180.78.6 with SMTP id x6mr19752668wiw.18.1330356691378 (num_hops = 1); Mon, 27 Feb 2012 07:31:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=WMHsgMaGTHD0IJEqr5sIQ+rF0+2pjWLuvC+d6tu0WGA=; b=YN1s9O7kj05pIkanXNZj3Cqy1erjA38XimvOoAmr8puCetIBv/IFYIsaR6IwxM0oW+ kgZulix17aNB0Nu+taftiR4o+jR8ymBKRpYBruNRtcZALw0AL5QRjeLlZn4McBCBKWw4 KuasZJ3/f31rDh9Vzp95SvA94SU5AtyED9deU= Received: by 10.180.78.6 with SMTP id x6mr15564849wiw.18.1330356691214; Mon, 27 Feb 2012 07:31:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.117.1 with HTTP; Mon, 27 Feb 2012 07:31:10 -0800 (PST) In-Reply-To: References: Date: Mon, 27 Feb 2012 17:31:10 +0200 Message-ID: To: Michael Morris Cc: "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) Michael Morris, Type hinting means that we have hints when declaring function/method signatures, example: functiion do(int $someVal) {} function doOther(string $str, mixed $pos = null) {} As I remember, there was never a discussion about adding type hints when declaring vars. The original discussion was and is about finishing the support for type hints because PHP allready has typehinting for arrays and objects. Additionaly there was launched a discussion about function/method return typehints. I do think the variable declaration type hints are pointless because variables are chaning their types on the fly. But mostly it will polute current discussion even more and adds a whole new super-global level of thinking through and implementation details. It's just too much. We had type hinting discussions for a few years now and never reached any conclusion and patches that have been made still had lots of problems. We should really focus on param type hints and maybe on return type hints for now and see where it takes us. Because the new thread has been created, I will leave my arguments here for the record. I, as a user land developer, would like the weak type hinting, which takes care of transparent conversions where no data loss is happening. I would like to get a E_NOTICE or E_WARNING when some loss is happening (for example I pass a string "aaa", but function expects an integer or double. It would convert it to 1, but also will emit the warning/notice for me to inspect what went wrong). And fatal errors on serious type miss match like it is now done with objects and arrays. This way is 100% backwards compatible, it does not add a ton of new rules to remember when write code and is based on the mechanics PHP already has, just extended a little. Same goes for the return type hints. The only case I do not remember being discussed in detail (maybe it was and I somehow missed that part) is when we accept (and return for return type hints) a mixed type param. Is it somehow described or we just leave out the type hints at all. It's not so rare to see something like this: function do(string $str = null). By logic it accepts 2 types - null and string, but type hint says it accepts only string and doing a call do(null) should work despite the type hint. My 2 cents.