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
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: 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: Sun Dec 22 03:01:28 2024 UTC