#20089 [Opn->Bgs]: Calling static method from instance method results in invalid $this

From: Date: Fri, 25 Oct 2002 17:03:36 +0000
Subject: #20089 [Opn->Bgs]: Calling static method from instance method results in invalid $this
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23327@lists.php.net to get a copy of this message
ID: 20089 Updated by: derick@php.net Reported By: dougqh@incogen.com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Solaris PHP Version: 4.2.3 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Also, this was discussed before (in both the bugdatabase and on the developer mailinglist) and this behavior will not be changed in the near future. Previous Comments: ------------------------------------------------------------------------ [2002-10-25 11:08:54] dougqh@incogen.com Here is an example ... <?php class Foo { function Foo() { $this->class = 'foo'; } function doCall() { return Bar::staticFunction(); } }; class Bar { function staticFunction() { if ( isset( $this ) ) { print 'This isset <br />'; print_r( $this ); } else { print 'Call as a static <br />'; } } }; $foo =& new Foo(); $foo->doCall(); ?> Note an instance of Foo is calling a static method of Bar. Bar does a test to see if $this is set. $this should not be set, since the method was statically invoked. Unfortunately, $this is set and its the instance of Foo that made the call to the static method of Bar. This bug makes writing methods that work both as static methods and instance methods virtually impossible. It is also extremely unsafe to allow Bar to access the member variables of Foo. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=20089&edit=1

« previous php.bugs (#23327) next »