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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Thu Mar 28 13:01:28 2024 UTC