Re: print_r unaware of object's read_property handler

From: Date: Thu, 15 Feb 2007 13:54:31 +0000
Subject: Re: print_r unaware of object's read_property handler
References: 1 2 3 4 5 6 7 8  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-4527@lists.php.net to get a copy of this message
mike@php.net (Michael Wallner) wrote: > > > > 1. "Register" object's properties in constructor ( using add_property_xxxx > > ) > > You should declare() default properties at MINIT. ce.default_properties and copy to getThis().value.obj.properties ? > > 2. Use standard get_properties handler which returns hash updated in constructor > > Where? Do not ask me. I "register" properties using add_property_xxx and do not define own get_properties hook which seems to work as properties are returned. No idea what's wrong and what's good here. > > 3. Use write and read property hooks to set GObject's Gvalue from zval or return > > zval from GValue. > > Fine. > > My suggestion for you: > HashTable *get_properties(zval *this_ptr TSRMLS_DC) > { > char *key; > HashTable *ht; > ALLOC_HASHTABLE(ht); //leaks, search archives > FOREACH_KEY(&Z_OBJCE_P(this_ptr)->default_properties, key) { > zval *prop = read_property(this_ptr, zval_with_key, 0 TSRMLS_CC); > ZVAL_ADDREF(prop); > zend_hash_update(ht, key, &prop); That's a point. I do not update hash because read_property doesn't use &prop. It uses only key here. Is it mandatory to call zend_hash_update? It will solve print_r problem but in such case I do not need read_property hook as I ca use standard one which should return value from hash. Piotras

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