Answer the question
In order to leave comments, you need to log in
Problem with duplicating properties in a class created in a C-extension?
Hello everyone,
I just recently started developing extensions for PHP and I can not understand why there is a duplication of properties in the class created in the extension. When creating a class, I do this:
STOPWATCH_INIT_CLASS(StopwatchEventNew) {
STOPWATCH_REGISTER_CLASS(Symfony\\Component\\Stopwatch, StopwatchEventNew, event, stopwatch_event_method_entry, 0);
zend_declare_property_string(stopwatch_event_ce, "category", sizeof("category")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(stopwatch_event_ce, "started", sizeof("started")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(stopwatch_event_ce, "periods", sizeof("periods")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
zend_declare_property_double(stopwatch_event_ce, "origin", sizeof("origin")-1, 0, ZEND_ACC_PRIVATE TSRMLS_CC);
return SUCCESS;
}
#define STOPWATCH_INIT_CLASS(name) int stopwatch_ ##name## _init(INIT_FUNC_ARGS)
#define STOPWATCH_REGISTER_CLASS(ns, class_name, name, methods, flags) \
{ \
zend_class_entry ce; \
memset(&ce, 0, sizeof(zend_class_entry)); \
INIT_NS_CLASS_ENTRY(ce, #ns, #class_name, methods); \
stopwatch_ ##name## _ce = zend_register_internal_class(&ce TSRMLS_CC); \
stopwatch_ ##name## _ce->ce_flags |= flags; \
}
PHP_METHOD(StopwatchEventNew, __construct)
{
zend_class_entry *ce;
double origin;
char *category;
int category_len;
zval *started, *periods;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|s", &origin, &category, &category_len) == FAILURE)
{
return;
}
ce = Z_OBJCE_P(this_ptr);
zend_update_property_string(ce, this_ptr, "category", sizeof("category"), category TSRMLS_CC);
zend_update_property_double(ce, this_ptr, "origin", sizeof("origin"), formatTime(origin TSRMLS_CC) TSRMLS_CC);
MAKE_STD_ZVAL(started);
MAKE_STD_ZVAL(periods);
array_init(started);
array_init(periods);
zend_update_property(ce, this_ptr, "started", sizeof("started"), started TSRMLS_CC);
zend_update_property(ce, this_ptr, "periods", sizeof("periods"), periods TSRMLS_CC);
}
val = zend_read_property(ce, this_ptr, "category", sizeof("category"), FALSE TSRMLS_CC);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question