Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56972 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10755 invoked from network); 21 Dec 2011 00:00:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Dec 2011 00:00:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=kassner@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kassner@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: kassner@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:50209] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/02-29615-A9121FE4 for ; Tue, 20 Dec 2011 19:00:27 -0500 Received: by wicr5 with SMTP id r5so1920780wic.29 for ; Tue, 20 Dec 2011 16:00:24 -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=ABtpbl0CiP2qTDvmz7pjPnd4Z1fP8eMfwPughs5DYP4=; b=EKM6uxXuI7UpzyzRgtF9nSC9fcG9V7bCwOBFtvBYeqRavq9uiGfWrN5NZ1LGLWe5iU tmsFHNt+iazamRqFY9QNHGMwvr82ijLulV3aZgyLrFM5GheOk5OwrVTPRPJIYyo0YXpW JQLZIncYFuoafnCK5Uij/AuutA+PFZGMdqtyg= Received: by 10.180.77.42 with SMTP id p10mr9233638wiw.5.1324425624235; Tue, 20 Dec 2011 16:00:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.105.212 with HTTP; Tue, 20 Dec 2011 16:00:03 -0800 (PST) In-Reply-To: References: <10ECF122-2487-4723-AD7B-A10C2EA3D318@gmail.com> Date: Tue, 20 Dec 2011 22:00:03 -0200 Message-ID: To: Mark Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] 5.3.8, Why is func_num_args() not working on a Clusure? From: kassner@gmail.com (Rafael Kassner) My bad, replied only to sender. Fixing it now. Well, any time you need to know signature or another information about a function or class method, you should use Reflection. func_num_args() is useful for when you need a dynamic function, like this (an hypothetic example using func_get_args(), but you can get the point). function delete () { $ids = func_get_args(); // implementation } $success = delete(1, 2, 7); On Tue, Dec 20, 2011 at 9:54 PM, Mark wrote: > Then there is no point for the func_num_args() function to accept a > parameter at all if it takes the current function anyway. > I don't see this as a feature, more like a bug! > > > On Wed, Dec 21, 2011 at 12:51 AM, Rafael Kassner wrote: >> >> func_num_args() must be called inside the Closure to know the number of >> arguments that it received. If you are calling outside, it returns the >> number of arguments of your testClosude function. There is no other way than >> Reflection to do this. >> >> And, I thunk func_num_args() does not receive any parameter. >> >> On Dec 20, 2011, at 9:43 PM, Mark wrote: >> >> > Hi, >> > >> > Why is func_num_args not working on closures? >> > Example code (tested on PHP 5.3.8): >> > >> > > > >> > class Test >> > { >> > public function testClosure($oClosure) >> > { >> > echo '
';
>> > print_r(func_num_args($oClosure));
>> > echo '
';
>> > }
>> > }
>> >
>> > $c = new Test();
>> > $c->testClosure(function($arg1, $arg2){
>> > });
>> >
>> > That returns 1 (the num of args in which function the closure is
>> > (testClosure), but not the number of args from the closure itself.
>> > Now Reflection can be used to get the number of args but that is
>> > overkill!
>> > Also when you would do print_r(func_get_args($oClosure)); you do get
>> > "something" back including the arguments but no way (that i know) to use
>> > them!
>> >
>> > Just something that i wonder...
>> > I would have expected num args to return the args of the function you
>> > provide it..
>> >
>> > Kind regards,
>> > Mark
>>
>



-- 
Atenciosamente,
Rafael Kassner