Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46111 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32431 invoked from network); 19 Nov 2009 18:33:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 18:33:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=doctorrock83@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=doctorrock83@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.227 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: doctorrock83@gmail.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:33413] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/0D-65535-E6F850B4 for ; Thu, 19 Nov 2009 13:33:19 -0500 Received: by fxm27 with SMTP id 27so2783040fxm.23 for ; Thu, 19 Nov 2009 10:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=qpnV2fu0w0mIHK3Y4pNVmO8WzIWu+keAaqPAIePZPS0=; b=TVX9h9dO6oA6orLMOH9+/zbAoayynqdo6vR7BpQlLiL9MRWXG0ZQjWofDQYDcZ1nXl xWT0ymBbJK+6ZLtWlrYJ3Rrt/pjMaQTPI3IUpz3oHja7xg0okbtsvA7h4mxwdsDoL0MO xCvmXmW8oXJ+3L1wBKQ5VO0UdhNcqO6ldNC4w= 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:content-transfer-encoding; b=r7cESVmMahB/3cLuiU1IAwF1aiQWeBAAFmwzUlEaanTzb9pRvQLReJ9Zk4ZNFITKEg ZelYVlXi0kA0Do82EkTjdOhpKNJNQmauQWiHZB9ibBdDBEMHbAohL+KuZ4y1zRoeVFZF YYZCX/KYs+UIkOQ7Eoa2vicAXNb1NJXuZZ50Q= MIME-Version: 1.0 Received: by 10.103.202.3 with SMTP id e3mr171782muq.55.1258655596142; Thu, 19 Nov 2009 10:33:16 -0800 (PST) In-Reply-To: <4B045234.1010804@zend.com> References: <4B045234.1010804@zend.com> Date: Thu, 19 Nov 2009 19:32:56 +0100 Message-ID: <72827a300911191032t249f9e1fi18a8fee476ed7dc0@mail.gmail.com> To: Stanislav Malyshev Cc: Jingcheng Zhang , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] The inconsistencies/flaws of PHP5's object model From: doctorrock83@gmail.com (Julien Pauli) On Wed, Nov 18, 2009 at 8:59 PM, Stanislav Malyshev wrote: > Hi! > >> I've just occured a syntax problem in the following script: >> >> > class C { >> =A0 =A0public $n =3D 1; >> } >> $o =3D new C(); >> $o->f =3D function () use ($o) { >> =A0 =A0echo $o->n; >> }; >> $o->f(); >> ?> >> >> The result of this script is "Fatal Error: Call to undefined method >> C::f()". >> I don't know this is the expected result. After trying more tests of > > Yes, this is the expected result. PHP is not Javascript, sorry :) Methods > and properties are different things in PHP, so the syntax assumes you ref= er > to method when you call $o->f(). You could use other syntaxes if you need= to > use a property as callable (see call_user_function, etc.). > call_user_func(array($o,'f')); leads to fatal error, I think the same internal mechanisms than $o->f() happens in call_user_func : the closure gets ignored but like Stas said : this could lead to problems with __get() and __call(). Anyway, for your use case to work, you should call $o->f->__invoke(); or call_user_func($o->f); Julien.Pauli