Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53209 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62413 invoked from network); 8 Jun 2011 12:46:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2011 12:46:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=felipensp@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=felipensp@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: felipensp@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-px0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:36291] helo=mail-px0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 30/12-48516-A3F6FED4 for ; Wed, 08 Jun 2011 08:46:51 -0400 Received: by pxi16 with SMTP id 16so288025pxi.18 for ; Wed, 08 Jun 2011 05:46:47 -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:from:date :message-id:subject:to:cc:content-type; bh=2133Z2NEsHD6VRsah8Ebb4PsIzwGNfbIc599ECj6zTE=; b=fUpDOODBT8/Jaf0zkPJAgwckTu1//UOL2akqHTC/zaCRoHcqp4gduJbvBt4Ok5UwuU 6YZJPiOwbR9Hy/4pMOJvMDiaIPBIO/5esM99+iIaPJ4/Ab+mYJ6G76QNu/TAAh25k6RT p63gZ2W2ZNmfI55Le9P3YMLmsjC5wxEJxtHrA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=wOfaBO7gu9tEheElM+u6Ejsk4QOplCZvtKhvG7V4T5vGFD3/srPYur49KX/YKlutT9 pPfV6fuxaa5fKCY/BUCmPv0mm5JD2UA+fQSBorC53visVx05shkr1xAmCvqZ2vwi725R Nvo6Qc9ebuZFrrNFacnjisVR5UvxUNm5NX5pQ= Received: by 10.143.61.19 with SMTP id o19mr253628wfk.347.1307537207134; Wed, 08 Jun 2011 05:46:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.246.21 with HTTP; Wed, 8 Jun 2011 05:46:26 -0700 (PDT) In-Reply-To: <4ec16f049f8a5946bca7e81ecec50b45@mohiva.com> References: <67f900ce904612afdba7650ccbed6ed4@mohiva.com> <4ec16f049f8a5946bca7e81ecec50b45@mohiva.com> Date: Wed, 8 Jun 2011 09:46:26 -0300 Message-ID: To: Christian Kaps Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001517588aacc308f704a532ba4f Subject: Re: [PHP-DEV] Re: $arr = array('Hello', 'world'); $arr(); From: felipensp@gmail.com (Felipe Pena) --001517588aacc308f704a532ba4f Content-Type: text/plain; charset=UTF-8 2011/6/8 Christian Kaps > On Wed, 8 Jun 2011 08:57:48 -0300, Felipe Pena wrote: > >> Hi, >> >> 2011/6/8 Christian Kaps >> >> Hi, >>> >>> >>> what happens if I use this code. >>> >>> class Foo { >>> >>> public $bar; >>> >>> public function __construct() { >>> >>> $this->bar = array($this, 'baz'); >>> $this->bar(); >>> } >>> >>> public function bar() { >>> echo 'bar'; >>> } >>> >>> public function baz() { >>> echo 'baz'; >>> } >>> } >>> >>> new Foo(); >>> >>> What is the output of this snippet? >>> >>> Are there the same rules as for closures? >>> >>> Christian >>> >>> >>> Yes, the same rules. >> > > Hi, > > I think for the sake of consistency it should be possible to use the > following code. > > class Bar { > > public function __construct($dispatcher) { > > $dispatcher->addEventListener('onUpdate', $this->onUpdate); > } > > public function onUpdate() {} > } > > If a property $onUpdate exists then it will be ignored. The same rules as > for Closures or for array callbacks. > > > Christian > > > > It works in the same way: class foo { public function __construct() { $this->bar = function () { return 1; }; // $this->bar(); // error $x = $this->bar; $x(); // ok $this->bar = array($this, 'baz'); // $this->bar(); // error $x = $this->bar; $x(); // ok } public function baz() { echo 'baz'; } } -- Regards, Felipe Pena --001517588aacc308f704a532ba4f--