php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34833 Incorrect this assignment
Submitted: 2005-10-11 21:18 UTC Modified: 2005-10-11 22:39 UTC
From: stochnagara at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.0RC1 OS: windows xp
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: stochnagara at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-10-11 21:18 UTC] stochnagara at hotmail dot com
Description:
------------
$this is assigned incorrectly. See the sample code below.

Reproduce code:
---------------
<?

class abc {
 function a() { echo "abc::a\n"; $this->b(); }
 function b() { echo "abc::b\n"; }
}

class def {
 function c() { echo "def::c\n"; abc::a(); }
}

$test = new def();
$test->c();


Expected result:
----------------
def::c abc::a
some error message

Actual result:
--------------
def::c abc::a
Fatal error: Call to undefined method def::b() in ...php on line 4


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-11 21:26 UTC] tony2001@php.net
Declare static methods as static, this way there won't be $this at all.
This is done to keep BC with PHP4 and won't change in the nearest future.
 [2005-10-11 22:39 UTC] stochnagara at hotmail dot com
Actually "Won't Fix" is a better bug status since it is not an expected behaviour. I expect an error message for example:) But that's not important.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 03:01:32 2025 UTC