Re: Re: Help on zend_hash_update

From: Date: Wed, 23 Aug 2000 21:43:41 +0000
Subject: Re: Re: Help on zend_hash_update
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-30433@lists.php.net to get a copy of this message
> On Wed, 23 Aug 2000, Gustavo Badauy wrote: > > I've created an object, that has a property called CurrentElement. I can > > read it easily inside the extension. Now, how can I update it? For example > > CurrentElement ++. > > > > The code is basically like that: > > > > zval *tmpVal; > > MAKE_STD_ZVAL(tmpVal); > > tmpVal->type = IS_LONG; > > tmpVal->value.lval = 1123; > > > > result = zend_hash_update (HASH_OF(*MyObject), "CurrentElement", > > strlen("CurrentElement") + 1, &tmpVal, sizeof(zval), NULL); > > You can either increment tmpVal directly (since a pointer to it is > stored in the hash table), i.e. Z_LVAL_P(tmpVal)++, or if you need to > retrieve the element first, do zend_hash_find() and then increment the > received zval. > > > Another question is regarding creating methods. This one I've posted on the > > php-dev and still didn't get any answer on that, if you have some time, and > > know how to solve it, please help me out. > If you mean how to create an object with methods? Look at ext/standard/dir.c. Its simple, every class has a function table, simply create your function table and then use the INIT_CLASS_ENTRY macro. example: static zend_class_entry *yourmod_ce_ptr; static function_entry php_yourmod_class_functions[] = { PHP_FE(meth1, NULL) PHP_FE(meth2, NULL) }; PHP_MINIT_FUNCTION(yourmod) { zend_class_entry yourmod_ce; INIT_CLASS_ENTRY(youmod_ce, "YourMod", php_yourmod_class_functions); yourmod_ce_ptr = zend_register_internal_class (&yourmod_ce); } PHP_FUNCTION(init_function) { object_init_ex(return_value, yourmod_ce_ptr); /* add properties you want, etc. */ } -Sterling

« previous php.dev (#30433) next »