php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19194 Static class usage, maybe bug maybe not
Submitted: 2002-08-30 05:59 UTC Modified: 2002-09-26 19:55 UTC
From: Jevgenijs dot Junkins at verdi dot lv Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.2.2 OS: Corel Linux
Private report: No CVE-ID: None
 [2002-08-30 05:59 UTC] Jevgenijs dot Junkins at verdi dot lv
I have a problem with static method usage (Classname::methodname())

here are two classes, for example:

<code>

class test1 {
  var $prop1;
  var $prop2;

  function test1($val1, $val2){
    $this->prop1 = $val1;
    $this->prop2 = $val2;
  }

  function test_method(){
   if($this){
     var_dump($this);
   }
   else {
     echo "do something"
   }
  }
 
}

class test2 {
  function test2(){
  }
  function run(){
    test1::test_method();
  }
}

t_obj = new test2();
t_obj->run();

</code>

I will always get output of var_dump, because in method of test1 test_method() $this is always set and it is reference or copy of initialized test2 class

Check of $this in test_method is required to check if it is static call or from this object, but it does not work, I think this is not correct behavior

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-09 10:46 UTC] stas@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip

Works for me with latest CVS (i.e., says "do something").
 [2002-09-26 19:55 UTC] sniper@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 13:01:33 2025 UTC