Re: [Zend Engine 2] Calling static method from object also sets $this

From: Date: Wed, 17 Apr 2002 13:27:59 +0000
Subject: Re: [Zend Engine 2] Calling static method from object also sets $this
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-82898@lists.php.net to get a copy of this message
I've seen it before (already last year) but was too busy. Now Richard Heyes and Tomas Cox brought it to my attention again. I first verified how the behaviour is with ZE2 (I don't think such changes will go into ZE1) and still saw the same issue. - Markus On Wed, Apr 17, 2002 at 03:09:05PM +0200, phpsurf wrote : > that's right ! I'm currently having the same problem with PHP 4.1.1 ! > I'm afraid this bug had never been seen before and that it should be sent to > the PHP-DEV list > > -----Original Message----- > From: Markus Fischer [mailto:mfischer@guru.josefine.at] > Sent: mercredi 17 avril 2002 14:00 > To: engine2@lists.zend.com > Subject: [Zend Engine 2] Calling static method from object also sets > $this > > > Hi, > > When calling a static method from an object, still the > variable $this is set to an object (the caller obejct) and > not NULL: > > <? > class parent_class { > > function parent_method() { > var_dump($this); > echo "class == " . get_class($this), "\n\n"; > } > } > > class extended_class extends parent_class { > > function call_static_method() { > parent_class::parent_method(); > } > > function call_parent_method() { > parent::parent_method(); > } > > function call_method() { > $this->parent_method(); > } > } > > $o = new extended_class; > $o->call_static_method(); > $o->call_parent_method(); > $o->call_method(); > parent_class::parent_method(); > ?> > > Output: > object(extended_class)(0) { > } > class == extended_class > > object(extended_class)(0) { > } > class == extended_class > > object(extended_class)(0) { > } > class == extended_class > > NULL > class == > > Although call_static_method() calls a static method, the > $this pointer is set in the method. This may work well for > parent:: calls but seems questionable for normal class:: > calls. > > It works if parent_method() is called from a function scope > ($this == NULL). > > This was originally pointed out by Richard Heyes for ZE1 and > I verified it with ZE2. > > I just think, when issuing a call to a static method, $this > should not be set. I may not foresee the implications with > that (except BC), but it seems locigal to me not to define > $this. > > regards, > - Markus > > -- > Please always Cc to me when replying to me on the lists. > GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc > "Mind if I MFH ?" "What QA did you do on it?" "the usual?" > "ah... none :)" > > > ______________________________________________________________________________ > ifrance.com, l'email gratuit le plus complet de l'Internet ! > vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP... > http://www.ifrance.com/_reloc/email.emailif > -- Please always Cc to me when replying to me on the lists. GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc "Mind if I MFH ?" "What QA did you do on it?" "the usual?" "ah... none :)"

« previous php.dev (#82898) next »