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

From: Date: Wed, 17 Apr 2002 13:09:05 +0000
Subject: RE: [Zend Engine 2] Calling static method from object also sets $this
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-82897@lists.php.net to get a copy of this message
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

« previous php.dev (#82897) next »