Re: print_r unaware of object's read_property handler
| From: | Michael Wallner | Date: | Thu, 15 Feb 2007 13:15:15 +0000 |
| Subject: | Re: print_r unaware of object's read_property handler | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4522@lists.php.net to get a copy of this message | ||
Piotr Pokora wrote:
> mike@php.net (Michael Wallner) wrote:
>
>> Piotr Pokora wrote:
>> [snip]
>>
>> Why don't you just implement a get_properties() handler where you
>> use your read_property() implementation then?
>
> Because get_properties hook which updates only keys in object's properties hash
> won't resolve the problem if your read_property hook doesn't return hash value.
>
> Point here is that I use underlying GObject object so read_property returns zval
> created from GValue, and object's properties hash has only keys wihout values
> assigned to them.
>
> Basic concept is:
>
> 1. "Register" object's properties in constructor ( using add_property_xxxx )
You should declare() default properties at MINIT.
> 2. Use standard get_properties handler which returns hash updated in constructor
Where?
> 3. Use write and read property hooks to set GObject's Gvalue from zval or return
> zval from GValue.
Fine.
My suggestion for you:
zval *read_property(zval *this_ptr, zval *member, int type TSRMLS_DC)
{
// custom
}
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);
}
return ht;
}
--
Michael