Re: PHP5 extensions: using existing functionnames as method names

From: Date: Wed, 13 Sep 2006 16:53:09 +0000
Subject: Re: PHP5 extensions: using existing functionnames as method names
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-25666@lists.php.net to get a copy of this message
zend_module_entry string_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "string", string_functions, PHP_MINIT(string), PHP_MSHUTDOWN(string), PHP_RINIT(string), /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(string), /* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(string), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; PHP_MINIT_FUNCTION(string) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "String", string_functions); string_ce = zend_register_internal_class(&ce TSRMLS_CC); string_ce->create_object = string_object_new; memcpy(&string_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
string_handlers.clone_obj = string_object_clone; return SUCCESS; } Problem #1 (The one you actually wrote about)
You're registering your methods twice. Once in zend_module_entry as global functions (the cause of your error), and again in INIT_CLASS_ENTRY() (The right place to be doing it). Solution: Change "string_functions" to "NULL" in zend_module_entry. Now for the rest of my complaints (all minor points):
stringclass.h Not a major problem, but this file naming will trip up static linking. So long as this is only ever a shared module you don't have any worry of course. But you might as well name it php_stringclass.h
#define STRING_METHOD(function_name) \ ZEND_NAMED_FUNCTION(c_stringclass_##function_name) #define STRING_ME(name, arg_info, flags) \ ZEND_FENTRY(name, c_stringclass_ ##name, arg_info, flags) There's nothing special about these macros except for the specific function prefix you assign them. Any particular reason you're using them?
#ifdef ZTS #define string_G(v) TSRMG(string_globals_id, zend_string_globals *, v) #else #define string_G(v) (string_globals.v) #endif It's common practice to use all uppercase for TSRM macros. Not really an issue, but worth a mentiCONFORM!!!!! YOU MUST CONFORM!!!! :)
-Sara

« previous php.internals (#25666) next »