Re: print_r unaware of object's read_property handler
| From: | Piotr Pokora | Date: | Thu, 15 Feb 2007 13:23:20 +0000 |
| Subject: | Re: print_r unaware of object's read_property handler | ||
| References: | 1 2 3 4 5 6 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4523@lists.php.net to get a copy of this message | ||
antony@zend.com (Antony Dovgal) wrote:
> > Is get_properties hook designed to return properties names with values?
>
> Yes.
Is this acceptable if get_properties return only names of properties?
Or is this an issue of my handler that print_r will not print values in such case?
If one of my hooks updates object's properties ( both keys and values ) ,
is this kind of overloading if I return zval using read_property and zval is not
returned from object's properties?
> >> You insist on implementing it like this:
> >>
> >> print_r(object)
> >> {
> >> property =
> >> object->read_property(<PROPERTY_NAME_TAKEN_DIRECTLY_FROM_YOUR_BRAIN>);
> >> print property;
> >> }
> >
> > No.
>
> You don't want to implement get_properties, but want to use read_property instead.
> Which means "yes".
I have a real use case , so real life example would be better ( php object using
underlying GObject object )
1. get_properties hook implemented using g_object_class_list_properties
Only property names are returned. So I have object's properties hash table updates (
without values )
2. read_property hook implemented using g_object_get_property
Property name is returned (?) from get_properties so I get GObject's property GValue
and return it as zval.
3. write_property hook implemented using g_object_set_property.
GValue is created from zval and property value is updated.
In such scenario , every OOP code works , except print_r.
> > print_r(object)
> > {
> > property = object.read_property(property_name_returned_from_get_properties);
> > print property;
> > }
>
> Because calling one function per operation is better then calling X functions, where X is the
> number of properties.
You mean hash_find VS get_properties and read_properties ?
print_r is rather not used in production environments and every developer would expect consistency
here.
Do you want to tell me "Yes , it's exception and we do not use read_property hook
here" ?
> >> > If yes, why print_r doesn't read property value using read_property hook,
> >> > even if I add own get_properties hook which
> >> > returns all properties names?
> >>
> >> Because get_properties() returns both names and values of the properties, we
> >> don't need to call read_property(),
> >> we already have the value in the has returned from get_properties().
> >
> > So get_properties and write_property hook should be enough?
>
> Which part of the sentence makes you think so?
"Because get_properties() returns both names and values of the properties"
Piotras