Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75511 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81878 invoked from network); 14 Jul 2014 22:16:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2014 22:16:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=park.framework@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=park.framework@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.172 as permitted sender) X-PHP-List-Original-Sender: park.framework@gmail.com X-Host-Fingerprint: 209.85.214.172 mail-ob0-f172.google.com Received: from [209.85.214.172] ([209.85.214.172:43889] helo=mail-ob0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/00-15121-4D654C35 for ; Mon, 14 Jul 2014 18:16:52 -0400 Received: by mail-ob0-f172.google.com with SMTP id wn1so4945418obc.17 for ; Mon, 14 Jul 2014 15:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=PssnKmYkNCq+4AuAGGTKNwzC37JeGgP2b+pxxJmFTj0=; b=pCvZ4Pw277E/yjZLut9VY8RzJsExJnszJQEqCTczcCy2SuQpPM4ziJK9CLFXpRrqyx kfmJHQiIDIQ4AdHHScJlHIRzg7Km1qO8XIW0q7czwLtXPZmQdkDDhJFXM4jyvi2dOBDC uTwIkCgDiDoLH/RDFRT6pYLlIBotnp+uppt8uXYBDr9y9UEidIGgV8F0ixoKtwZ4Igne bW/Pd9YDCVtnfdm5xcrMCaOKBidokY28EXVWtTtNk+j7wST6kXijiCxHvCtLGNjCrYBL waIE9hiQotu8UhkX8exXqIe2TjqCZj2hxGYkJmnaQEJn7ydUT1sKL24+byT2YKi4I3g4 q9SA== MIME-Version: 1.0 X-Received: by 10.60.33.35 with SMTP id o3mr16681847oei.7.1405376209345; Mon, 14 Jul 2014 15:16:49 -0700 (PDT) Received: by 10.76.27.226 with HTTP; Mon, 14 Jul 2014 15:16:49 -0700 (PDT) In-Reply-To: References: Date: Tue, 15 Jul 2014 01:16:49 +0300 Message-ID: To: Chuck Reeves Cc: PHP internals Content-Type: multipart/alternative; boundary=089e011842a6bbe15404fe2ea524 Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: park.framework@gmail.com (Park Framework) --089e011842a6bbe15404fe2ea524 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Maybe we should make two different syntax? fun(int $num, array $list) - for strict type compliance fun((int) $num, (array) $list) - converted to type It will be very obvious, and without magic. 2014-07-14 23:23 GMT+03:00 Chuck Reeves : > 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 wi= th > 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 th= e > 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 solutio= n between > > strict and just casting. The hope is to appease both sides and provide > the > > most workable solution, really. It=E2=80=99s also the style that I, mys= elf, like > > best, because it=E2=80=99s strict enough to catch bugs (I like that), a= nd 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 > > > > > --089e011842a6bbe15404fe2ea524--