Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60119 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22752 invoked from network); 17 Apr 2012 22:32:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2012 22:32:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:59054] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/47-21594-57FED8F4 for ; Tue, 17 Apr 2012 18:32:22 -0400 Received: by ggmb2 with SMTP id b2so3854270ggm.29 for ; Tue, 17 Apr 2012 15:32:19 -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=aPNL89Imasfec2pjkpKKU6MiujXGuScqR4hB3dsPtxw=; b=C7MusVX2+8h34REEt79HxFPytQWMuxKnCgWvUTmiEINnznSJxxMX0jPKUH+f91YPCq mcbUMLPrJbHbovAtvg6Dgr7L5+NNGhvyeHdVCNWcp0K2Bk+tPA7g1JfUuTK4b4O/3d0p Kjif3omV6+CjBFUbkEJX7ZGXFGIv0wh/n79p5RufKQqeqEij3bQtr4NvX7d/JTxT9NBv RdiY95CZD8NgmS7LeKZXJa0+ewUso/3pY7sNO6UsBN6PJcRS7v4viaGF18g1kC038yjG owb8h7VmURnxhBWNOJmEZ88HKUcK8CnXtoC3NBILzvH5p7E3PBhAnzRJoph4EkEQ3QDJ Tu5Q== Received: by 10.236.170.197 with SMTP id p45mr16984473yhl.86.1334701939263; Tue, 17 Apr 2012 15:32:19 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.146.86.14 with HTTP; Tue, 17 Apr 2012 15:31:39 -0700 (PDT) In-Reply-To: <4F8DEA47.9060706@php.net> References: <4F8DE877.1010600@php.net> <4F8DEA47.9060706@php.net> Date: Wed, 18 Apr 2012 07:31:39 +0900 X-Google-Sender-Auth: SYpyDoxndNaJwxj-mtSjthlqMDc Message-ID: To: Stefan Neufeind Cc: php-dev Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Variable-length args by reference From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi, 2012/4/18 Stefan Neufeind : > On 04/18/2012 12:02 AM, Stefan Neufeind wrote: >> Hi, >> >> the topic of variable argument-lists for functions in connection with >> getting the parameters by reference came up. This is currently not >> possible with func_get_args(), though a "hack" with debug_backtrace() is >> possible. >> >> How would you think about extending func_get_args() and func_get_arg() >> to allow for: >> >> =A0 =A0 =A0 $args =3D func_get_args(FUNC_GET_ARGS_BY_REFERENCE); >> =A0 =A0 =A0 $arg0 =3D func_get_arg (0, FUNC_GET_ARGS_BY_REFERENCE); >> >> (default would be FUNC_GET_ARGS_BY_COPY) >> >> >> Currently only the following "hack" works: >> >> function calc() >> { >> =A0 =A0 =A0 $d =3D debug_backtrace(); >> =A0 =A0 =A0 =A0 $args =3D $d[0]['args']; >> =A0 =A0 =A0 =A0 $args[0] *=3D 2; >> =A0 =A0 =A0 =A0 $args[1] *=3D 2; >> } >> >> $a =3D 5; >> $b =3D 7; >> var_dump ($a, $b); >> calc(&$a, &$b); >> var_dump ($a, $b); > > Hmm, that example also only works because of the call-time > pass-by-reference? *sigh* > Sorry, I forgot those ampersands in the call to calc(). Doesn't work > without. > > I hope the idea is clear though. Any chance we might make this possible > through func_get_args()? I don't know what you would like to do, but function calc(&$args =3D NULL) { var_dump(count($args)); // num of args $args[1] *=3D 2; } calc(array(1,2,3,4)); would work. Regards, -- Yasuo Ohgaki