static_members?

From: Date: Fri, 23 Dec 2005 14:56:39 +0000
Subject: static_members?
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3358@lists.php.net to get a copy of this message
Hi, I've tried to figure out the way to assign variables passed through static function to static members before it gets new instanced. Suppose there is a script class as follows: class Sample { protected static $var = null; static function set_var($val) { self::$var = $val; } static function get_var() { return self::$var; } } and suppose c-code is like below (omitting unnecessary parts) zend_class_entry *sample_ce; PHP_METHOD(sample, get_var); PHP_METHOD(sample, set_var); function_entry sample_method[] = { PHP_ME(sample, set_var, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(sample, get_var, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) {NULL, NULL, NULL} }; PHP_METHOD(sample, get_var) { /* zend_std_get_static_property might be used, but * scares about updating ce->static_member since * it's real global variable and always pointer to same address. */ } PHP_METHOD(sample, set_var) { /* this implementation is questionable. */ } PHP_MINIT(some_module_name) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "Sample", sample_method); /* make sure object_init_ex call default init routine * since own ctor, dtor is not used in this case. */ ce.create_object = NULL; sample_ce = zend_register_internal_class(&ce TSRMLS_CC); sample_ce->ce_flags = ZEND_ACC_PUBLIC; zend_declare_property_null(sample_ce, "var", strlen("var"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); } set_var() implementation might be possible if: 1. using module-globals that holds the value or hashtable itself. 2. might be possible? if ptr is set to new zval. or Is there any appropriate way? Thanks, H.D

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