Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53199 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34038 invoked from network); 8 Jun 2011 10:17:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2011 10:17:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=hannes.magnusson@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=hannes.magnusson@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: hannes.magnusson@gmail.com X-Host-Fingerprint: 74.125.83.42 mail-gw0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:58081] helo=mail-gw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/CD-50253-64C4FED4 for ; Wed, 08 Jun 2011 06:17:42 -0400 Received: by gwb17 with SMTP id 17so139261gwb.29 for ; Wed, 08 Jun 2011 03:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=AFAEnb+zi3ChamEGSdElJRFYDW3SeRuFzi6QpXaKTiU=; b=WGxfnsW9dGwrqHtoaO46Eh07LzfVDbT5VcaBgc4BBBYg/HQFbkXWS6P3/R8mB50yRX fjsZB3Zn5ne34Y3HCCSx043N+ZgRmqnt3e4ctQo5dy+B1bxwqGocZd06X1d2mnFK/jhm oGJXDQdcIF2L1tHryAEjcDv3KvijwcqYRmqtY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=GrE9XA1mxausTOiVN9cfAOPwGs8YljXQac8Drmuf2lUuLPqXOA41UaPOR8Gu6Fl0Bk ISVJq7tNUPJfnDEVfym+zT+RKxtrsZiVppxblmSz/M4x22zWX6m4iffqhUp6Sq0WE0/h 2IQ4iMPPEOY0mW6mfL7v+3h/jCuy6WNDaHsVw= MIME-Version: 1.0 Received: by 10.150.56.38 with SMTP id e38mr467890yba.113.1307528258366; Wed, 08 Jun 2011 03:17:38 -0700 (PDT) Received: by 10.146.210.3 with HTTP; Wed, 8 Jun 2011 03:17:38 -0700 (PDT) In-Reply-To: <1307527464.3635.395.camel@guybrush> References: <4DED3D5B.6030307@oracle.com> <4DEE782E.1020605@sugarcrm.com> <1307489981.23373.31.camel@guybrush> <1307527464.3635.395.camel@guybrush> Date: Wed, 8 Jun 2011 12:17:38 +0200 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Stas Malyshev , "Matthew Weier O'Phinney" , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Callable type From: hannes.magnusson@gmail.com (Hannes Magnusson) 2011/6/8 Johannes Schl=C3=BCter : > On Wed, 2011-06-08 at 10:38 +0200, Hannes Magnusson wrote: >> 2011/6/8 Johannes Schl=C3=BCter : >> > On Tue, 2011-06-07 at 12:12 -0700, Stas Malyshev wrote: >> >> Hi! >> >> >> >> > https://wiki.php.net/rfc/callable >> >> >> >> It is good there's an RFC. However it seems to lack code examples. I >> >> understand it may be obvious to the proposers how it looks like, but >> >> it'd be nice to have the actual example there as it is done nearly >> >> everywhere else. >> > >> > The RFC is missing information about what happens in codebases which >> > already have a "callable" type declared. Will that be prevented or wil= l >> > they hit a runtime error? ("callable expected, callable type found") >> >> You mean an interface/class with that name? >> The error would be 'expected instanceof callable, string/array/closure r= ecieved. >> >> gettype("strpos") will still return a string, not callable. >> >> A callable wouldn't be fully featured type. > > Which means that > =C2=A0 class callable { } No. 'callable' is a parser token. >> > What about default values? Will >> > =C2=A0 =C2=A0function foo(callback $cb =3D 'strpos') { } >> > be valid? >> >> No default values, other then NULL allowed. >> Otherwise we would need to support array("classname", "methodname") >> too, and then people would want default array values for array >> typehinting etc etc etc. > > Ok. I assume NULL as default value would be allowed, though. This would > be consistent for the language and allow such things: > > function foo(callback $cb =3D NULL) { > =C2=A0 =C2=A0if (!$cb) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0$cb =3D function() { /* .. default implementat= ion */ > =C2=A0 =C2=A0} > =C2=A0 =C2=A0.... > } Etienne pointed out that default values for arrays can actually contain val= ues.. I actually had no idea. I suppose we then need to support default values for an array callable. But yes, a callable can have the default value of null, following the rules of class hinting. -Hannes