php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33980 $this refers to the caller in static calls
Submitted: 2005-08-03 15:52 UTC Modified: 2005-08-03 16:21 UTC
From: gerald at copix dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.3 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gerald at copix dot org
New email:
PHP Version: OS:

 

 [2005-08-03 15:52 UTC] gerald at copix dot org
Description:
------------
$this refers to the caller in static calls of non-static methods.

If the function is correctly set as static, then $this is ok.

That may be a problem as I'm provinding a library that has to be PHP4/PHP5 compliant. 

(in PHP4, "$this" would have not been set)

Reproduce code:
---------------
$obj = new Caller ();
$obj->showResult ();

class Caller {
 function showResult (){
  echo StaticClass::staticCallAsOfPHP4 ();
 }
}

class StaticClass {
 static function staticCallAsOfPHP4 (){
  return (isset ($this)) ? get_class ($this) : 'none';
 }
}

Expected result:
----------------
"none "
(because of the static call, as of PHP4)

Actual result:
--------------
"Caller"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-03 15:56 UTC] derick@php.net
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

.
 [2005-08-03 16:19 UTC] gerald at copix dot org
My mistake, next time I'll pay more attention to the 
documentation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 17:01:29 2024 UTC