Re: Re: calling protected PHP_METHOD via call_user_function; missing context ??

From: Date: Tue, 06 Jan 2009 02:56:28 +0000
Subject: Re: Re: calling protected PHP_METHOD via call_user_function; missing context ??
References: 1 2 3 4 5 6  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6039@lists.php.net to get a copy of this message
On Mon, Jan 5, 2009 at 1:17 PM, Henrique M. Decaria <typoon@gmail.com>wrote: > 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). i remember thinking about this when i first wrote this block, but didnt find anything convincing to create separate variables at that time. ive since created separate vars for each class / interface declaration, per your suggestion. > 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). > nice tip; done! > 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); this is what i tried first after H=Johannes, mentioned there were several wrapper methods. but when i try the macro, php run-tests.php takes *read* forever, and when i dump the output of one of my tests, theres some error messages about missing symbols.. dyld: Symbol not found: _zend_call_method_with_0_params Referenced from: /opt/local/lib/php/extensions/no-debug-non-zts-20060613/pure_mvc.so do i need to include another header or something, the macro is in zend_interfaces.h, so i assumed it should be available.. > 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. i see youve used the constructor in the class entry for the fn_proxy here, but in my case the method i want is not defined on the class entry, but it looks like i could call zend_hash_find() up front if i want; only i dont think it matters so much unless you want to leverage some caching feature, which im pretty unclear about at this point. atm, im just going for the basics so NULL it is for fn_proxy :D Check it out and see if that works for you. well the second tip was really nice and the examples and so forth, very helpful. im afraid that didnt get my code working, but theres some good news; i figured it out :D so, i realized i had this code *above* the code i was struggling w/, and it wasnt even working; i just glossed over it in haste or something, if(zend_hash_exists(&puremvc_macrocommand_ce->function_table, "addsubcommand", strlen("addSubCommand")+1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "addSubCommand found"); } so i realized the message wasnt getting printed out; and i decided to focus on that bit of code. well somehow i realized that since the methods / functions are lowercase in php, you have to pass the method name as all lower case; duh! so this code works if(zend_hash_exists(&puremvc_macrocommand_ce->function_table, "addsubcommand", strlen("addsubcommand")+1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "addSubCommand found"); } and now, a similar revision makes the call to initializeMacroCommand work as well ;) 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. well i knew id reveal some of my C ignorance if i posted; heh. thanks again, to both of you, -nathan

« previous php.pecl.dev (#6039) next »