Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75510 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75755 invoked from network); 14 Jul 2014 20:24:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2014 20:24:00 -0000 Authentication-Results: pb1.pair.com header.from=chuck.reeves@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chuck.reeves@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.177 as permitted sender) X-PHP-List-Original-Sender: chuck.reeves@gmail.com X-Host-Fingerprint: 209.85.213.177 mail-ig0-f177.google.com Received: from [209.85.213.177] ([209.85.213.177:55476] helo=mail-ig0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/E0-03625-F5C34C35 for ; Mon, 14 Jul 2014 16:24:00 -0400 Received: by mail-ig0-f177.google.com with SMTP id hn18so2107781igb.10 for ; Mon, 14 Jul 2014 13:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=biQQeMxpdAsVwD2xmCWtjniNEILvGQfkWkN9FueESvY=; b=b2ddUg1f6Sy4shkM/Qy/lhui75Iv95AcjFN7xkHLggTQSSOY8GC8F3oHVEAe1V/WIj tgRClA+LZkJtzaLv5IWFF2LWC86vHBE4Q8Q+i03IBIM+6elwBVOeGzSbwi6By9YZpKuG VD2gCb0biW7Nn0GToAGYNetdrNrjP8ebQjYGnDNtNQERHMuR2pfKgai4btGrD8low1Ao IP8VAKP0ThhIlEDChXp+ZtMnMxQ8AtC0f3PM8vG6cn9qqd9Mt3HBCpeo/dJ+XUvvX2FK 7kFrHBzkzmoRgvJHK2MXujMkrmx6OKhjplY3sFZy+G+klDh2oxY6lS3MYbBRHSOgFXeA dS2w== MIME-Version: 1.0 X-Received: by 10.42.186.2 with SMTP id cq2mr24327592icb.25.1405369436873; Mon, 14 Jul 2014 13:23:56 -0700 (PDT) Received: by 10.64.18.228 with HTTP; Mon, 14 Jul 2014 13:23:56 -0700 (PDT) Date: Mon, 14 Jul 2014 16:23:56 -0400 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf303ea8e810288b04fe2d12f4 Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: chuck.reeves@gmail.com (Chuck Reeves) --20cf303ea8e810288b04fe2d12f4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I am new to the list and internals so my question might be obvious to others: Why even cast the variable? When I look at a function and see: function myFunc(array $someData) { //some processing } I understand that myFunc requires an array passed in. If I try to call myFunc like so: myFunc('foobar'); I get a fatal error stating that I did not pass in an array. If I try with stdClass: myFunc(new \stdClass()); I will get the same error however If I cast the object before passing in like so: myFunc((array) new \stdClass()); It works just fine. The benefit of having the hint tells whom ever is going to consume the function that the parameter needs to be casted to the scalar type. If I have this: function addTwoValues(int $valueOne, int $valueTwo); It is clear that i need to make sure I'm using int's. If I try to call that function with any other type, I would like to get the error instead of some kind of auto-magical cast into something that could product strange results. I think the benefit is in having the hint with excluding the cast of the value. Let the user cast the value to what the function requires. IMHO Allow the author of the function to dictate what is needed to execute. On Mon, Jul 14, 2014 at 3:59 PM, Andrea Faulds wrote: > > On 14 Jul 2014, at 20:53, Rowan Collins wrote: > > > The debate in this thread basically comes down to us each wanting our > favourite from that list of features to have the privilege of dedicated > syntax in function signatures. > > That=E2=80=99s why this RFC is supposed to be a best-compromise solution = between > strict and just casting. The hope is to appease both sides and provide th= e > most workable solution, really. It=E2=80=99s also the style that I, mysel= f, like > best, because it=E2=80=99s strict enough to catch bugs (I like that), and= it keeps > PHP a type-shifting language (I like that too). > > -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf303ea8e810288b04fe2d12f4--