Re: print_r unaware of object's read_property handler

From: Date: Thu, 15 Feb 2007 13:34:56 +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-4524@lists.php.net to get a copy of this message
antony@zend.com (Antony Dovgal) wrote: > > 1. "Register" object's properties in constructor ( using add_property_xxxx > > ) > > 2. Use standard get_properties handler which returns hash updated in constructor > > 3. Use write and read property hooks to set GObject's Gvalue from zval or return > > zval from GValue. > > > > This approach works pretty fine for OOP , but fails with print_r which expects fully > > updated hash properties. > > Could you elaborate on this and explain what you mean by "fails"? "Register" object's properties in constructor ( using add_property_xxxx ) case G_TYPE_STRING: add_property_string(zobject, (gchar*)props[i]->name, "", 1); break; case G_TYPE_UINT: case G_TYPE_INT: add_property_long(zobject, (gchar*)props[i]->name, 0); and so on. I do not assign values to properties at this point and standard get_properties returns correct hash table for object's properties. 2. Use standard get_properties handler which returns hash updated in constructor 3. Use write and read property hooks to set GObject's Gvalue from zval or return zval from GValue. read: g_object_get_property(G_OBJECT(gobject), Z_STRVAL_P(prop), &pval); MAKE_STD_ZVAL(_retval); php_midgard_gvalue2zval(&pval, _retval); write: GValue *gvalue = php_midgard_zval2gvalue(value); g_object_set_property(gobject, Z_STRVAL_P(prop), gvalue); std_hnd->write_property(zobject, prop, value TSRMLS_CC); So "fails" means that property's value is not returned by print_r, though read_property hook seems to be ok as <?php echo $object->propA; ?> works fine. >This approach seem to work pretty fine for everybody but you. Because I do not use object's properties hash to store values. I have these values already assigned to GObject values. How PHP5-GTK2 implements it? Copy GTK object properties to zend object's hash table? Piotras

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