php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25220 Statically called members can access $this
Submitted: 2003-08-23 11:19 UTC Modified: 2003-12-01 03:36 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at koert dot bitfactory dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2003-08-23 (dev) OS: Cygwin/win2k
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at koert dot bitfactory dot nl
New email:
PHP Version: OS:

 

 [2003-08-23 11:19 UTC] php at koert dot bitfactory dot nl
Description:
------------
If a static method is called from an objectcontext, $this is accessible from that objectcontext.
$this should be out of scop in the static method...

Reproduce code:
---------------
class static_class {
   function static_func() { echo $this->variable;  }
}

class testclass {
   function func() { static_class::static_func(); }
}
$x = new testclass();
$x->func();




Expected result:
----------------
<br />
<b>Fatal error</b>:  Using $this when not in object context in <b>[filename]</b> on line <b>2</b><br />

Actual result:
--------------
No output (thus no error)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-28 20:46 UTC] sniper@php.net
Output with latest CVS:

PHP Notice:  Undefined property:  testclass::$variable in /home/jani/t.php on line 4

 [2003-11-29 07:11 UTC] php at koert dot bitfactory dot nl
Still not fixed, it produces the wrong error. It should warn about $this, not about $variable.
I am cvsupping as we speak, but i assume thie following testcase still doesn't produce an error:

class static_class {
   var $variable="Variable in static_class.";
   function static_func() { echo $this->variable;  }
}

class testclass {
   var $variable="Variable in testclass.";
   function func() { static_class::static_func(); }
}
$x = new testclass();
$x->func();
 [2003-12-01 03:35 UTC] sniper@php.net
You need to use 'static' in the function declaration
to make it work like you expect. (otherwise it behaves like in PHP4..)

 [2003-12-01 03:36 UTC] sniper@php.net
static function static_func() { echo $this->variable;  }

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 18:01:28 2024 UTC