Re: How do I register a constructor in PHP (C code)

From: Date: Tue, 25 Sep 2001 18:22:57 +0000
Subject: Re: How do I register a constructor in PHP (C code)
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-66579@lists.php.net to get a copy of this message
I believe the problem you are having is that the zend_class_entry structure destroyed as you leave the scope of the MINIT function. This is definitely going to have undefined behavior. Move the zend_class_entry so that it is global and you should be good to go. Jeff Hughes jeffh@apptechsys.com On Tue, Sep 25, 2001 at 05:12:37PM +0300, Emanuel Dejanu wrote: > > I write an extension and I want to register a new class > but I can not get my function to be registered as a constructor. > > ex: > PHP_FUNCTION(rt66class_constructor); > static zend_function_entry php_rt66class_class_functions[] = > { > PHP_FALIAS(RT66Class, rt66class_constructor, NULL) > }; > > PHP_MINIT_FUNCTION(rt66util) > { > zend_class_entry rt66class_class_entry; > INIT_CLASS_ENTRY(rt66class_class_entry, "RT66Class", > php_rt66class_class_functions); > RT66Class_class_entry_ptr = > zend_register_internal_class(&rt66class_class_entry); > > return SUCCESS; > } > > PHP_FUNCTION(rt66class_constructor) > { > ZEND_PUTS("RT66Class Contructor"); > } > > > ----- > <?php > dl(myext.so); > $myvar = RT66Class(); > ?> > > nothing appear on the screen. > > Please tell me how can I make it to work. > > Many thanks, > > Emanuel Dejanu > > > -----Original Message----- > > From: Andy [mailto:andy@php.net] > > Sent: Wednesday, August 01, 2001 3:27 PM > > To: php-dev@lists.php.net > > Subject: Fwd: FW: [PHP-DEV] print_r > > > > > > > > > > ---------- Forwarded Message ---------- > > Subject: FW: [PHP-DEV] print_r > > Date: Wed, 1 Aug 2001 08:19:09 +0300 > > From: "Emanuel Dejanu" <edejanu@route66.ro> > > > > > > Sorry to forward this to you but I really have problems in > > printing a doubled linked class. > > Can you take a look at the following message and give me > > an answer. > > > > Thanks, > > > > Emanuel Dejanu > > > > -----Original Message----- > > From: Emanuel Dejanu [mailto:edejanu@route66.ro] > > Sent: Tuesday, July 31, 2001 9:22 AM > > To: php-dev@lists.php.net > > Subject: [PHP-DEV] print_r > > > > > > > > Hi, > > > > Is there a posibility to print an object but to not print some fields. > > > > If I use print_r he will print all variabiles from my object, > > but I want on > > variabile to not be printed. I do not want to write my own function. > > Ex. > > > > class Node { > > var $name; > > var $parent = '/' > > var $children = array(); > > function Node($name, &$parent) { > > $this->parent = &$parent; > > $this->name = $name; > > } > > } > > > > $rootNode = new Node('root', ''); > > array_push($rootNode->children, new Node('child1', $rootNode)); > > $child1Node = &$rootNode->children[0]; > > array_push($child1Node->children, new Node('child1', $child1Node)); > > > > print_r($rootNode); > > > > will print make a recursivity. What will be nice is to allow that some > > variabiles to not > > be printed like this: > > > > class Node { > > var $name; > > var $__parent = '/' > > var $children = array(); > > function Node($name, &$parent) { > > $this->__parent = &$parent; > > $this->name = $name; > > } > > } > > > > ..... /* add the root and childrens */ > > > > print_r($rootNode); > > > > will print now the corret tree. > > > > Bellow you find the only modification that need to be done > > for this to work. > > > > Best regards, > > > > Emanuel Dejanu > > > > > > File: Zend/zend.c > > > > static void print_hash(HashTable *ht, int indent) > > { > > zval **tmp; > > char *string_key; > > HashPosition iterator; > > unsigned long num_key, str_len; > > int i, key_type; /****** HERE *****/ > > > > for (i=0; i<indent; i++) { > > ZEND_PUTS(" "); > > } > > ZEND_PUTS("(\n"); > > indent += PRINT_ZVAL_INDENT; > > zend_hash_internal_pointer_reset_ex(ht, &iterator); > > while (zend_hash_get_current_data_ex(ht, (void **) > > &tmp, &iterator) == > > SUCCESS) { > > > > > > /******** HERE **************/ > > > > key_type = zend_hash_get_current_key_ex(ht, > > &string_key, &str_len, > > &num_key, 0, &iterator); > > if (key_type == HASH_KEY_IS_STRING) > > if (string_key[0] == '_' && > > string_key[1] == '_') continue; > > > > > > /******* HERE **************/ > > > > > > for (i=0; i<indent; i++) { > > ZEND_PUTS(" "); > > } > > ZEND_PUTS("["); > > switch (key_type) { > > case HASH_KEY_IS_STRING: > > ZEND_PUTS(string_key); > > break; > > case HASH_KEY_IS_LONG: > > zend_printf("%ld",num_key); > > break; > > } > > ZEND_PUTS("] => "); > > zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT); > > ZEND_PUTS("\n"); > > zend_hash_move_forward_ex(ht, &iterator); > > } > > indent -= PRINT_ZVAL_INDENT; > > for (i=0; i<indent; i++) { > > ZEND_PUTS(" "); > > } > > ZEND_PUTS(")\n"); > > } > > > > > > -- > > PHP Development Mailing List <http://www.php.net/> > > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > > For additional commands, e-mail: php-dev-help@lists.php.net > > To contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > ------------------------------------------------------- > > > > -- > > PHP Development Mailing List <http://www.php.net/> > > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > > For additional commands, e-mail: php-dev-help@lists.php.net > > To contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#66579) next »