Re: print_r unaware of object's read_property handler

From: Date: Thu, 15 Feb 2007 13:04:37 +0000
Subject: Re: print_r unaware of object's read_property handler
References: 1 2 3 4 5  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-4520@lists.php.net to get a copy of this message
On 02/15/2007 03:39 PM, Piotr Pokora wrote:
Is get_properties hook designed to return properties names with values?
Yes.
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.
You don't want to implement get_properties, but want to use read_property instead. Which means "yes".
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; }
Because calling one function per operation is better then calling X functions, where X is the number of properties.
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?
That's not what I said. You need both get_properties() and read_property() in most cases.
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?
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>
Oh, do you want to invest some time in the docs? Believe me, it would be really appreciated.
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.
Enough for what? Could you be more clear when asking questions, so I wouldn't have to guess?
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.
Oh, yes, you can ask and even expect someone to answer you. Though I wouldn't expect to get answers on questions which require several days to investigate, you should understand that. Personally I'm just not ready to spend that much time on it. -- Wbr, Antony Dovgal

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