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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
23 + 8 = ?
Subscribe to this entry?

 
 [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: Wed Apr 24 00:01:32 2024 UTC