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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 11:01:30 2024 UTC