Re: print_r unaware of object's read_property handler
| From: | Piotr Pokora | Date: | Fri, 16 Feb 2007 09:47:29 +0000 |
| Subject: | Re: print_r unaware of object's read_property handler | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4549@lists.php.net to get a copy of this message | ||
antony@zend.com (Antony Dovgal) wrote:
> > The simplest solution seems to be update default_properties of class pointer returned by
> > zend_register_internal_class. It should work for derived classes too, right?
>
> I believe the simplest solution would be to use the recommended solution instead of inventing
> the wheel and developing odd theories, including OO ones.
> You're trying to do something really weird, no wonder you have problems with its
> implementation.
No, Antony. I do not try to do something weird.
I expect you are familiar with GObject basic functionality, and your suggestion
will kill performance and provide anything but code reuse.
I just wrote simple test. it looks like this (briefly):
read_property handler hook:
g_object_class_find_property(
G_OBJECT_GET_CLASS(gobject), Z_STRVAL_P(prop));
g_object_get_property(G_OBJECT(gobject), Z_STRVAL_P(prop), &pval);
MAKE_STD_ZVAL(_retval);
php_midgard_gvalue2zval(&pval, _retval);
g_value_unset(&pval);
/* I do not use get_properties hook here */
get_properties handler hook:
php_error(E_WARNING, "GET PROP");
zend_object *zobj;
zobj = Z_OBJ_P(zobject);
return zobj->properties;
BTW, I added Z_OBJ_P to my .c file. Why it's not available as public macro?
PHP code:
$obj = new midgard_config();
$obj->method();
echo " $obj->prop_A \n";
print_r($a);
Output:
Warning: GET PROP in /home/pp/cvs/midgard/src/apis/php4/aa.php on line 9
Warning: GET PROP in /home/pp/cvs/midgard/src/apis/php4/aa.php on line 11
abc
midgard_config Object
Warning: GET PROP in /home/pp/cvs/midgard/src/apis/php4/aa.php on line 13
So , conclusion is very simple:
If I would like to follow your suggestion , I should produce following code for
only <?php echo $obj->prop; ?> :
g_object_list_properties /* list all properties, only names */
g_object_class_find_property /* ensure it's base class */
g_object_get_property /* get property because I need to update object's hash
properties */
g_object_class_find_property /* we're in read property hook and I can not get
value from zend hash , ensure it's base class*/
g_object_get_property /* get gobject's property and return */
I am asking about updating ce.default_properties because I can reduce overhead
of calling g_object_list_properties and g_object_class_find_property.
Or even if I can not do this, I can follow get_properties convention if I can
define my own refcount for opaque struct used for underlaying GObject.
Then I can update propertis hash ones and next return only properties as it's
done in ZEND's default get_properties handler.
From performance point of view I can update hash properties in write_property
hook. Thus , only ( and only when property is indeed written ).
I use PHP5 from debian unstable repo. If php_error(E_WARNING, "GET PROP"); in
get_properties hook works as should work , then it means that you overload your
swish object by updating hash table all over again and again.
But maybe this is your approach. I do not know.
So , to sum up. All I need is to use ZEND's default get_properties handler and
update properties hash only once. I must be sure , that implementation is going
to work for derived classes. That's why I asked about ce.default_properties.
You say I am trying to do something weird.
Michael says it's the way to go.
So , should I come back to "use the force, read the source" and trial and error
work. Or should I define for whom I trust here?
Piotras