|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-04-27 20:37 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 22:00:01 2025 UTC |
> 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. okay, but in PEAR (pear/Mail/RFC822.php) is following code: class Mail_RFC822 { /** * A variable so that we can tell whether or not we're inside a * Mail_RFC822 object. * @var boolean $mailRFC822 */ var $mailRFC822 = true; function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null) { if (!isset($this->mailRFC822)) { $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit); return $obj->parseAddressList(); } ... here an other script will use this classfunction with Mail_RFC822::parseAddressList($bla,..). is this a php bug, because now we could not test whether or not we're inside a object?