Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53200 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35953 invoked from network); 8 Jun 2011 10:28:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2011 10:28:18 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:33821] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/2E-50253-0CE4FED4 for ; Wed, 08 Jun 2011 06:28:17 -0400 Received: by qwi4 with SMTP id 4so168102qwi.29 for ; Wed, 08 Jun 2011 03:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc:content-type; bh=s78uXbMHWCdBXIK8Yim0NopSa/3T71TXzeTyzP0Q4Lo=; b=Vxk4N2L0CGo6buppjBpyBJEvqMZpW8a/4Nu8Ua1nt9pZ3mPxMhNX7ZoIYXVXiL0eME PC6x5KCUqXOwBWB26k4SFGrFey/UOOq9Xj/wwkKTak9po4AZMY8ZwFO2d/dS77dEhITo HDGVLJQs6MCiQ9Q4srSS0O0c/pTbF1c1ZhdUU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; b=tLkUmNScyFtpb10ZoWVDeFUQeGtt7iu24wCX4VdW9v4y5ZoaOOPguuHTIG4ZbaK8ak ZnwFco662/X9T1TYeqzT5Bwe34UwUZjxkWlvvPQ9rSaTYgJkzCVISnFTjO2zAR23w6m5 n3gZBfO4dWMU6bZpwaYXlUCmSJg9CKbJrg2dI= Received: by 10.229.95.144 with SMTP id d16mr5298256qcn.37.1307528894081; Wed, 08 Jun 2011 03:28:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.80.79 with HTTP; Wed, 8 Jun 2011 03:27:54 -0700 (PDT) Reply-To: RQuadling@GMail.com In-Reply-To: References: <4DED3D5B.6030307@oracle.com> <4DEE782E.1020605@sugarcrm.com> <7104F8AD-489E-4824-97AA-D9831FAB77AA@bitextender.com> <4DEE8ABB.8040503@sugarcrm.com> <7E4C6CB6-ED93-4BFC-87B8-94FDEF243896@bitextender.com> <17.29.50253.ACD8EED4@pb1.pair.com> <41.0E.50253.11B9EED4@pb1.pair.com> Date: Wed, 8 Jun 2011 11:27:54 +0100 Message-ID: To: Alexey Shein Cc: Hannes Magnusson , "Matthew Weier O'Phinney" , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Callable type From: rquadling@gmail.com (Richard Quadling) On 8 June 2011 09:47, Alexey Shein wrote: > 2011/6/8 Hannes Magnusson : >> We have the situation in the docs that parameters declared as arrays >> do not follow the typehinting rules, but parameters as class names do. >> Re-using the callback from the docs could get confusing when >> extensions start to typehint on it, but not the core.. >> >> I think there is a subtle difference between a callback, and a callable. >> In javascript for example, callback is something that is executed on >> certain events "onsuccess" is the typical example. >> There is nothing that says the callable parameter gets executed as a >> part of an event, and I think the default usecase would be to execute >> it right away (f.e. filtering data). >> >> I think I would prefer callable, but I could live with either. >> > > Wikipedia defines callback as "a reference to executable code, or a > piece of executable code, that is passed as an argument to other > code". So there's no "event" meaning put by default, it's just very > often seen callback's usage in javascript. > I just like "callback" term more :) An interesting issue here. Closures, classes with an __invoke method and strings containing existing function names all pass is_callable() and can be called using (). But, array('class', 'method') also passes is_callable, but isn't a callback. http://pastebin.com/Yb5nJ8DB outputs ... object is callable Invoked : Wed, 08 Jun 2011 11:24:09 +0100 object is callable Closure : Wed, 08 Jun 2011 11:24:09 +0100 string is callable Wed, 08 Jun 2011 11:24:09 +0100 array is callable Handling Array via call_user_func Func array : Wed, 08 Jun 2011 11:24:09 +0100 So, callable and callbacks are 2 different things. Callable 1 - closures. 2 - classes with an __invoke method. 3 - strings to an existing function. 4 - array('class', 'method') Callbacks Only 1, 2 and 3 from the above list. If you try to use $funcarray(), you get the following fatal error ... Fatal error: Function name must be a string -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea