php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38697 access method from other object with call_user_func
Submitted: 2006-09-03 08:52 UTC Modified: 2006-09-04 08:36 UTC
From: totol at tele2 dot fr Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.4.4 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: totol at tele2 dot fr
New email:
PHP Version: OS:

 

 [2006-09-03 08:52 UTC] totol at tele2 dot fr
Description:
------------
if you call a static method with call_user_func in an object, you don't have access to var of the caller object, see code bellow

Reproduce code:
---------------
class myClass {
   var $myVar="hello";
   function staticCall(){
       myClass2::method();
   }
   function calluserCall(){
       call_user_func(array('myClass2','method'));
   }
}
class myClass2{
    function method(){
       echo $this->myVar;
    }
}
$test=new myclass();
$test->staticCall();    //return 'hello'
$test->calluserCall();   //return nothing


Expected result:
----------------
$test->staticCall();    //return 'hello'


$test->calluserCall();   //return nothing



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-04 08:36 UTC] tony2001@php.net
PHP4:
hello
Notice: Undefined variable:  this in /tmp/2.php on line 14

PHP5:

Strict Standards: Non-static method myClass2::method() should not be called statically, assuming $this from incompatible context in /tmp/2.php on line 6
hello
Strict Standards: Non-static method myClass2::method() cannot be called statically in /tmp/2.php on line 9

Strict Standards: Non-static method myClass2::method() cannot be called statically in /tmp/2.php on line 9
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC