Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54250 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88754 invoked from network); 29 Jul 2011 09:44:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2011 09:44:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:51116] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/F1-07983-0E0823E4 for ; Fri, 29 Jul 2011 05:44:01 -0400 Received: by vwl1 with SMTP id 1so2952484vwl.29 for ; Fri, 29 Jul 2011 02:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=+ppfRp3wSy/NNzVjA24/yIBGOLk3UTRHQpxzrXY//jg=; b=cMqQcjdnbRe1Bfvw3NvPs7Fb+2qBapU9uFzQUG3++Eufq5RqQm+rCirobMWSSt6XlT D6ThvG0pDFh3fjfIGUxEV38D+t8OIcSjIaHekEDEj+9Uh+StqKT+OqnSfuXSlaEUud9M S++5KlIK/PwsDF9fBKaXDnKMX3JuZ781SCFHY= MIME-Version: 1.0 Received: by 10.220.20.133 with SMTP id f5mr269424vcb.270.1311932638296; Fri, 29 Jul 2011 02:43:58 -0700 (PDT) Sender: laruence@gmail.com Received: by 10.220.161.130 with HTTP; Fri, 29 Jul 2011 02:43:57 -0700 (PDT) In-Reply-To: References: Date: Fri, 29 Jul 2011 17:43:57 +0800 X-Google-Sender-Auth: ufByl-mUFWU_xS2sYdsY9bd4TBY Message-ID: To: Etienne Kneuss Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Bug #55311] Static methods invoke __call when called from within class From: laruence@php.net (Laruence) Hi: hmm, this make sense, thanks for your explaining. 2011/7/29 Etienne Kneuss : > Hello, > > On Fri, Jul 29, 2011 at 11:10, Laruence wrote: >> Hi: >> >> 2011/7/29 Etienne Kneuss : >>> Hi, >>> >>> On Fri, Jul 29, 2011 at 05:37, Laruence wrote: >>>> Hi: >>>> =C2=A0 =C2=A0 about #55311.https://bugs.php.net/bug.php?id=3D55311 >>>> >>>> =C2=A0 =C2=A0 I found it maybe for some reason, that somebody change t= he >>>> if/elseif sequence to make this bug. >>>> >>>> =C2=A0 =C2=A0 but I am not sure about why he do this, =C2=A0so I refer= to maillist, =C2=A0any idea? >>> >>> This is not a bug. >>> >>> If you call a method using the Foo::bar() syntax, you don't >>> necessarily get a static call. >>> >>> A static call is made if either: >>> >>> 1) the target method is declared as static >>> 2) There is no compatible object context at the time of the call. >> >> I was wondering does this is well-documented? =C2=A0since when? > > It is not documented that way no, but it has always been documented > that :: can be used to access overriden members in a non-static way. > The actual rules behind static calls is a bit more general though, as > described here. > >> >> obviously, it is BC break to PHP 5.3.3. >> > > To me it's simply a bug fix. > Consider the following code: > > class A { > =C2=A0 public function __call() { > =C2=A0 =C2=A0 =C2=A0 echo "__call"; > =C2=A0 } > > =C2=A0 public function __callStatic() { > =C2=A0 =C2=A0 =C2=A0 echo "__callStatic"; > =C2=A0 } > } > > class B extends A { > =C2=A0 public function test() { > =C2=A0 =C2=A0 =C2=A0parent::test(); > =C2=A0 } > } > > > $b =3D new B; > > $b->test(); > > It would simply be wrong to have callStatic being called here (it > always called __call before __callStatic existed), so IMO the new > behavior is fine, and even though fixing it introduced a BC break > (like many bug fixes), it is now more consistent. Note that reverting > it again would introduce a BC break as well with current 5_3. > > Best, > >> in PHP 5.3.3 __staticCall is in the front of the if/elseif statements. >> >> so I was very interesting to know why this was changed >> >> >> thanks, ;) >> >>> >>> In this case, it is not a static call, as the method is undeclared >>> (hence cannot be declared as static) and you do have a compatible >>> object context. So __call is used, not __callstatic. >>> >>> Best, >>> >>>> >>>> =C2=A0 =C2=A0Index: Zend/zend_object_handlers.c >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>>> --- Zend/zend_object_handlers.c (revision 313905) >>>> +++ Zend/zend_object_handlers.c (working copy) >>>> @@ -988,13 +988,13 @@ >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!fbc && zend_hash_find(&ce->function_ta= ble, lc_function_name, >>>> function_name_strlen+1, (void **) &fbc)=3D=3DFAILURE) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0efree(lc_functi= on_name); >>>> >>>> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ce->__call && >>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ce->__callstati= c) { >>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return zend_get_user_callstatic_function(ce, function_name_strva= l, >>>> function_name_strlen); >>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (ce->__ca= ll && >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0E= G(This) && >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Z= _OBJ_HT_P(EG(This))->get_class_entry && >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0i= nstanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return zend_get_user_call_function(ce, function_name_strval, >>>> function_name_strlen); >>>> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (ce->__ca= llstatic) { >>>> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return zend_get_user_callstatic_function(ce, function_name_strva= l, >>>> function_name_strlen); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return NULL; >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>>> -- >>>> Laruence =C2=A0Xinchen Hui >>>> http://www.laruence.com/ >>>> >>>> -- >>>> PHP Internals - PHP Runtime Development Mailing List >>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>> >>>> >>> >>> >>> >>> -- >>> Etienne Kneuss >>> http://www.colder.ch >>> >> >> >> >> -- >> Laruence =C2=A0Xinchen Hui >> http://www.laruence.com/ >> > > > > -- > Etienne Kneuss > http://www.colder.ch > --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/