Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60213 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97506 invoked from network); 19 Apr 2012 09:26:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2012 09:26:57 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:47460] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/40-29087-06ADF8F4 for ; Thu, 19 Apr 2012 05:26:56 -0400 Received: by yenl5 with SMTP id l5so4785730yen.29 for ; Thu, 19 Apr 2012 02:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=TlI4lr/eg/FiNfDTcxNKem8VPnXKTCrS9EdVZwPt6Gg=; b=0fUows7RiUNog00AmY/ObQ5lv3/xHduj2xZ2ERbgjNqL+jlahKA4mL6NG56KhRLcOB f/myrlG/OYoo1Qiv7xOSlZDW6zu/lKEa4Lfp/BRh9JIhfD0K6oRMaBN3ozGI2/K8+eje s5znejZmGuLfYtH8DaCoiVpgFw2LPmnOEvGynM4kAtAQyS0VOmz/oxEXuubj5+eCd+lQ GGB38vDAhXzUPYX+LztE6addTvtyBILfpijkVHli8ttOXgKoISNajvAqzcEMVppU3Tpb cZfRI9rUbebDaVM3QijcMn50+VGzRwwiNy7asLKR6u21hfeA5MPfxHxvQX2s12B2csce Ni8Q== Received: by 10.236.170.197 with SMTP id p45mr1148510yhl.86.1334827613513; Thu, 19 Apr 2012 02:26:53 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.146.86.14 with HTTP; Thu, 19 Apr 2012 02:26:13 -0700 (PDT) In-Reply-To: References: <4F8DF4B1.2040307@sugarcrm.com> Date: Thu, 19 Apr 2012 18:26:13 +0900 X-Google-Sender-Auth: Fpk6k0UhxdLWuKyiZZr9Lt0sfYc Message-ID: To: Daniel Macedo Cc: Adam Jon Richardson , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] skipping optional parameters From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi, Just a though for named parameter, since it seems its becoming a relevant topic now. 2012/4/18 Daniel Macedo : > I'll keep going offtopic a bit more. > I would rather see named parameters implemented *prior* to this. > Although maybe not instead, I think both might have their place. > > On Wed, Apr 18, 2012 at 08:43, Yasuo Ohgaki wrote: >> >> Something like >> >> setcookie( name:'mycookie', value:'abc', secure:true, httponly:true ); >> >> is really nice to have. Source code will be much more readable. >> > > I agree with this!=A0But for short array syntax we kept the =3D>=A0as in > $array =3D ["foo" =3D> "bar"]; > Not sure if this was a limitation, lack of that suggestion or a > decision; but the shortest syntax it's still not... (as Yoda would > say!) > > $array =3D ["foo": "bar"]; doesn't look weird to me, plenty readable, > and that's the shortest! Object can be used as named parameter in JavaScript. // Define function to take one "argument", which is in fact an object: function fnParseInt( oArg ){ return parseInt( oArg.number, oArg.radix ); } // Which you then call like this (pass in an object literal): fnParseInt( { number : 'afy', radix : 36 } ); If there is a JSON like syntax for PHP objects, named parameter can be implemented just like this. It would not work for function that accepts object as first parameter, but who cares? Pros. - simple - everyone are used to JSON and JavaScript now a days - supporting JSON syntax is convenient for other purpose - internal functions may support this. (Single object parameter for this) - coexists func($a,,,,$b) Cons - loose type hints - loose default values for params - yet another script injection risk if we do "eval($json_data)" (json_decode() should be used, anyway.) We may use array to emulate JavaScript, though. fnParseInt(['number'=3D>'afy', 'radix'=3D>36]); It's many typing compare to other languages, but it works. If we are going to have array like syntax, we may just use array. Anyway, I'm not sure what happened for annotation. Annotation maybe used as type hints, etc. Just an idea that I think of now. There might be many better ideas for named parameter. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net