#28189 [Opn->Bgs]: call_user_func, not in object context when called by class and func name
| From: | derick@php.net | Date: | Tue, 27 Apr 2004 19:18:22 +0000 |
| Subject: | #28189 [Opn->Bgs]: call_user_func, not in object context when called by class and func name | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-58880@lists.php.net to get a copy of this message | ||
ID: 28189
Updated by: derick@php.net
Reported By: hrvinnie at yahoo dot com
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Debian Kernel 2.2.20-idepci
PHP Version: 5.0.0RC2
New Comment:
This is not a bug, the error message here is totally correct as there
is no instance of this class in your script, so you can't access $this
here.
Previous Comments:
------------------------------------------------------------------------
[2004-04-27 20:37:58] hrvinnie at yahoo dot com
Description:
------------
PHP4 allowed one to call a function using call_user_func by passing in
an array containing the class name and function name as strings.
In PHP5RC1 and PHP5RC2, I have found the function is getting called.
However, using $this-> within the function triggers a fetal error.
My appologies, I was not sure what the best "Type" for this was, or if
I'm crazy and doing something bone head wrong.
Reproduce code:
---------------
class test_call_user_func
{
var $created = "false";
function __construct()
{
$this->created = "true";
}
function isCreated()
{
$ret = $this->created;
return $ret;
}
}
$function = array('test_call_user_func', 'isCreated');
print ("I have a return of isCreated [" . call_user_func($function) .
"]" );
Expected result:
----------------
I have a return of isCreated [true]
Actual result:
--------------
Fatal error: Using $this when not in object context in
/home/vfabello/workspace/loki/root/test3.php on line 16
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28189&edit=1