Re: Re: calling protected PHP_METHOD via call_user_function; missing context ??
| From: | Henrique M. Decaria | Date: | Mon, 05 Jan 2009 11:58:41 +0000 |
| Subject: | Re: Re: calling protected PHP_METHOD via call_user_function; missing context ?? | ||
| References: | 1 2 3 4 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-6036@lists.php.net to get a copy of this message | ||
Oops... sorry Nathan. I was talking to Felipe and he just called my
attention that the '==1' would be right. I verified the code for
zend_hash_exists and in fact it really returns 1 when the property is
exists.
Is there any chance you could paste the whole code, or give a url to a
pastebin of it? I'd like to see how you are creating the method for the
class MacroCommand.
Sorry for the mistake :X
Henrique
On Mon, Jan 5, 2009 at 5:42 AM, Henrique M. Decaria <typoon@gmail.com>wrote:
> Nathan,
>
> Not sure of this line here:
>
> if(zend_hash_exists(&this_ce->
>>
>> function_table,
>> "initializeMacroCommand", sizeof("initializeMacroCommand")) ==
>> 1) {
>
>
> Why are you using '== 1' ? Perhaps you should use '== SUCCESS'. SUCCESS is
> a macro that is expanded to '0'. So zend_hash_exists will either return 0 or
> -1. I guess that is the reason why it is always going inside the else block.
> Test it and see if that works :)
> Also, why are you casting all those NULLs ?
>
> Regards,
>
> Henrique
>
>
> On Thu, Jan 1, 2009 at 5:36 PM, Nathan Nobbe <quickshiftin@gmail.com>wrote:
>
>> 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
>>
>
>