Re: $this availability inside static-functions

From: Date: Thu, 21 Jul 2005 20:09:45 +0000
Subject: Re: $this availability inside static-functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-17369@lists.php.net to get a copy of this message
Sean Coates schrieb: >> how can i check if a method is called statically when called from inside >> another object? (without debug_bactrace()) > > <plug > > type="own">http://blog.phpdoc.info/archives/4-Schizophrenic-Methods.html</plug> > > Short answer: > $isStatic = !(isset($this) && get_class($this) == __CLASS__); i know this hack, but it does not work, if the statically called method is from the same class as the calling object class foo { function bar() { if ( isset( $this ) && get_class( $this ) == __CLASS__ ) { return 'not static'; } return 'static'; } function bar2() { return foo::bar(); } } // returns 'static' echo foo::bar(); // returns 'not static' but should be 'static' $foo = new foo; echo $foo->bar2(); -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetime www.sf.net/projects/phptimesheet

« previous php.internals (#17369) next »