Re: non static function called as static one

From: Date: Wed, 11 Mar 2009 22:12:32 +0000
Subject: Re: non static function called as static one
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-43319@lists.php.net to get a copy of this message
On Wed, Mar 11, 2009 at 3:16 PM, Olivier Doucet <webmaster@ajeux.com> wrote: > Hello, > > I posted the same topic on the general mailing list, but it appears this > can > be posted here, as it is open to feedbacks and is about PHP implementation > of static functions. > > I'm wondering if the following behaviour is a bug or a feature. The case is > quite complex, so let me explain my point of view. > here is the source : > > <?php > > class MyTest { > public function myfunc() { > echo get_class($this); > } > } > class MySecondTest { > public function test() { > MyTest::myfunc(); > } > } > > $test = new MySecondTest(); > $test->test(); //output: "MySecondTest" > > ?> not sure if this was mentioned on the general list but, i believe what youre describing is documented in the manual under php5 classes/objects -> "the basics": http://www.php.net/manual/en/language.oop5.basic.php $this is a reference to the calling object (usually the object to which the method belongs, but can be another object, if the method is called statically <http://www.php.net/manual/en/language.oop5.static.php> from the context of a secondary object). -nathan

« previous php.internals (#43319) next »