Re: calling protected PHP_METHOD via call_user_function; missing context ??
| From: | Nathan Nobbe | Date: | Thu, 01 Jan 2009 23:36:53 +0000 |
| Subject: | Re: calling protected PHP_METHOD via call_user_function; missing context ?? | ||
| References: | 1 2 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-6030@lists.php.net to get a copy of this message | ||
On Tue, Dec 30, 2008 at 2:11 PM, Johannes Schlüter <johannes@php.net> wrote:
> On Tue, 2008-12-30 at 13:11 -0700, "Nathan Nobbe" wrote:
> > call_user_function(&this_ce->function_table, &this, callback,
> &retval,
> > 0,
> > (zval**)NULL TSRMLS_CC);
>
> use zend_call_method - the second parameter there is the CE of the
> calling scope. See Zend/zend_interfaces.h there are few wrappers, too.
thanks for your quick response. i switched over to zend_call_method passing
a casted NULL for the fn_proxy, which just means im not leveraging some
caching feature, right?
anywasys, i was getting the same error even w/ zend_call_method, so i
decided to wrap this code in an outer call to zend_hash_exists. then i
raise a fatal if its not found (at least for now during development). turns
out, the error message is coming up every time, but im not sure why..
if i do php --rc i can see the MacroCommand::initializeMacroCommand, i have
an implementation, its just and empty block right now, but i assumed that
would be sufficient, im using the function_table in the zend_class_entry,
which i get by first using getThis() and then using zend_get_class_entry(),
that seems like it should be the correct function_table.
any more advice for a newb ? heres the code ive got atm
/* {{{ proto public void MacroCommand::__construct()
Constructor. */
PHP_METHOD(MacroCommand, __construct)
{
zval *this, *retval;
zend_class_entry *this_ce;
this = getThis();
this_ce = zend_get_class_entry(this);
array_init(return_value);
zend_update_property(this_ce, this, "subCommands",
sizeof("subCommands")-1,
return_value TSRMLS_CC);
if(zend_hash_exists(&this_ce->function_table,
"initializeMacroCommand", sizeof("initializeMacroCommand")) == 1) {
retval = NULL;
zend_call_method(&this, this_ce, (zend_function**)NULL,
"initializeMacroCommand",
sizeof("initializeMacroCommand"), &retval,
0, (zval*)NULL, (zval*)NULL TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_ERROR,
"MacroCommand::initializeMacroCommand was not found!");
}
}
/* }}} */
-nathan