Re: Re: calling protected PHP_METHOD via call_user_function; missing context ??
| From: | Henrique M. Decaria | Date: | Mon, 05 Jan 2009 20:17:07 +0000 |
| Subject: | Re: Re: calling protected PHP_METHOD via call_user_function; missing context ?? | ||
| References: | 1 2 3 4 5 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-6038@lists.php.net to get a copy of this message | ||
Nathan,
I myself am also new to PHP ext dev. Let me raise some points here where I
had trouble these last days, that might also be causing issues for you.
First one is in the PHP_MINIT_FUNCTION. When you register your classes you
are doing it as:
1. INIT_CLASS_ENTRY(ce, "MacroCommand",
puremvc_macrocommand_class_methods);
2. puremvc_macrocommand_ce = zend_register_internal_class_ex(&ce,
3. puremvc_notifier_ce, NULL TSRMLS_CC);
I see you are re-using the 'ce' variable everytime you register a class.
That should work fine, but I had major issues doing that, so I decided to go
with one variable for each class I was registering (I think it is work a try
creating a new temp class entry var here just to make sure).
Second point is:
Move the declaration of your class entries (from line 1133 to line 1155) to
the begginig of the the code, and inside the __construct function for your
class (MacroCommand), instead of having this line: this_ce =
zend_get_class_entry(this); // Line 124
simply use the puremvc_macrocommand_ce variable (no need for this_ce then).
Third point is:
When I had to call a method (I was calling the __construct of the object in
my code), I used the zend_call_method_with_X_params where X is a number >=
0. These methods are defined in zend_interface.h ( you will need to include
it in your code).
Here is an example on how I call it in my code:
zend_call_method_with_0_params(&sdl_syswmmsg_instance, class_SDL_SysWMmsg,
&class_SDL_SysWMmsg->constructor, "__construct", NULL);
Where:
sdl_syswmmsg_instance - is a zval* with the instance of the object (like
getThis() would give you)
class_SDL_SysWMmsg - is the zend_class_entry of the object
class_SDL_SysWMmsg->constructor - is the fn_proxy
"__construct" - is the name of the method I am calling.
Check it out and see if that works for you.
About casting the NULLs, I was just wondering why you did that. My point is,
a NULL is always a NULL so I don't think so you need to cast it. Just use
NULL and that might be fine.
Hope this helps.
Henrique
On Mon, Jan 5, 2009 at 11:26 AM, Nathan Nobbe <quickshiftin@gmail.com>wrote:
> On Mon, Jan 5, 2009 at 4:42 AM, Henrique M. Decaria <typoon@gmail.com>wrote:
>
>> Also, why are you casting all those NULLs ?
>>
>
> let me just post the signature in the mail for reference,
>
> zval* *zend_call_method* ( zval** object_pp, zend_class_entry* obj_ce,
> zend_function** fn_proxy, char* function_name, int function_name_len, zval**
> retval_ptr_ptr, int param_count, zval* arg1, zval* arg2, magic TSRMLS_DC )
>
> & my call to it
>
> zend_call_method(&this, this_ce, (zend_function**)NULL,
> "initializeMacroCommand",
> strlen("initializeMacroCommand"), &retval,
> 0, (zval*)NULL, (zval*)NULL TSRMLS_CC);
>
> so for the third argument, zend_function** fn_proxy, when looking at the
> zend_interfaces.c, the method appears to try and find the method given then
> first two arguments when the third param is NULL;
>
> if (!fn_proxy && !obj_ce) {
> /* no interest in caching and no information already present that
> is
> * needed later inside zend_call_function. */
>
>
> but if you do supply the third arg then it looks like zend_call_method,
> will leverage some caching mechanism, is that correct?
>
> regarding the NULL's in params 8 & 9; i have no parameters to pass to this
> MacroCommand::initializeMacroCommand, which is why i set param_count to 0,
> and params 8 & 9 to NULL.
>
> as for the call to zend_hash_exists, i regret to say after posting last, i
> was actually encountering this error,
>
> Fatal error: Couldn't find implementation for method
> MacroCommand::initializeMacroCommand in Unknown on line 0
>
> which is not what i put in my last post, which therefore made it
> misleading, and i appologize for that. anyway, i wanted to see if ive made
> a bad call to zend_call_method, so i thought; well, lets just see if
> initializeMacroCommand is actually in that hash in the first place (the one
> that comes from the getThis() macro). well turns out, its not, and now im
> left wondering why..
>
> this is sort of what i was alluding to in my last post. if i do php --rc
> MacroCommand on the cli, for example, initializeMacroCommand is there in the
> output. so, im thinking it must be in the HashTable ?? apparently im doing
> something wrong here, but still sort of stabbing at the air.
>
> ive got tons of more code to write on this so, i may just move on to other
> areas and revisit this issue later.
>
> at any rate, ive posted what i have so far for the extension.
>
> http://pastebin.com/m5b723e3
>
> im not a complete newb w/ C, but im not proficient either. im trying to
> develop my C skills here, and i really appreciate the help from you folks on
> the list :D
>
> -nathan
>
>