Re: print_r unaware of object's read_property handler
| From: | Piotr Pokora | Date: | Thu, 15 Feb 2007 12:39:26 +0000 |
| Subject: | Re: print_r unaware of object's read_property handler | ||
| References: | 1 2 3 4 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4517@lists.php.net to get a copy of this message | ||
antony@zend.com (Antony Dovgal) wrote:
>
> Ok, show me in a pseudo-code how are you going to clap with only one hand, i.e. to use
> read_property() without knowing the property name.
This is impossible, and it's not my point.
I do not use read_property hook for voodoo "guessmyname" functionality.
I use it to return zval for property with name X.
This is the approach of read_property right?
> This is how it works atm:
>
> print_r(object)
> {
> properties = object->get_properties();
>
> while(properties) {
> print *properties;
> properties++;
> }
> }
Is get_properties hook designed to return properties names with values?
Or names are enough to read property with read_property hook which knows the name
returned by get_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.
I expect clarification why:
print_r(object)
{
property = zend_hash_find
print property;
}
is better than
print_r(object)
{
property = object.read_property(property_name_returned_from_get_properties);
print property;
}
> If you need to get only names of the properties, you can use keys of the hash returned by
> get_properties().
> But returning only keys without the values does not make any sense, since it would require
> implementing and calling BOTH get_properties()
> AND read_property(), and the latter would be called for each property, adding a slowdown.
You want to tell me that it's better implementing get_properties which updates hash table (
keys and values )
and do not define read_property hook?
> > 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?
> > Yes, of course I can implement get_properties hook that way so it can updates
> > object's properties hash.
> > But my question is: do I need such functionality if my read_property ( and write ) hook
> > doesn't need object's properties hash?
>
> Don't use it if you don't need it.
Yes, but print_r prints only property names then :)
> > Or better , do I need to duplicate every property's value in hash table because
> > print_r doesn't use my read_property handler?
>
> "Duplicate every property's value"?
> Have you ever heard of functions and code reuse?
<only_joke>
Have you ever heard about specs and docs?
</only_joke>
> > Obvious answer is that such hook must update object's properties hash.
> > But why, if the only one purpose is print_r and var_dump functions?
>
> $object->property = "new value";
This is done in write_property hook. That's why I askded above if write_property and
get_properties hooks are enough.
> > And I think the last question:
> > When and why object's read_property hook is ignored?
>
> I don't think you really expect me to go over the sources and explain every internal
> function to you, do you?
"Those who know don't talk.
Those who talk don't know."
I will add my own "Those who do not know, ask".
So I think I am at correct list.
Piotras