Re: unique identifier for zvals in user-land?

From: Date: Sat, 02 Sep 2000 21:04:08 +0000
Subject: Re: unique identifier for zvals in user-land?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-31686@lists.php.net to get a copy of this message
That's a very good explanation, which completely convinces me we mustn't let memory addresses get to userland at any cost :) Zeev At 21:59 02/09/2000, André Langhorst wrote:
I fear this is a bad practice. Hiding unnecessary information is one of the basic rules of modular design. That means, if you need some "internal ID" of the variable, you are probably doing something wrong. Also, this would force the language to guarantee you invariancy of this ID, which adds another complication.
Yeah, I´ve just figured out that memory adresses are a bad thing for this and even if zend internally uses IDs for values I would not be able to find them again once a ref-count has reached zero, because that get_variable_id() function would of course return another ID because the memory has been freed meanwhile.
Really, what would you need this for?
caching by value, regardless of input type+performing well even if input is object or array. I want to identify *values* in a function, if they´ve been passed before or not. The only way this is currently possible, is to store *every* value as an index in an associative array. The drawback then is that the object I`m storing these values in grows and grows, resources won´t be freed up until the end of the request (because they are stored as an index) and eventually large copies will occur if you´re placing objects and arrays into that array. The function code equals the previous example in the first mail to understand what it´s used for (attached below). Summarizing now I think that there is no "clean" and "always well performing" way to do this, the method I choosed is perhaps the best approach. Another safe method would be to md5() the output of var_dump() of a value and store this string as an index for caching, but that´s a way not performing very well... andré attachments ------------ current approach (w/o optimization per type):
function cache_result($input)    {
if (!isset($this->cache_result[$input]))    {
$this->cache_result[$input]=calculate_somthings($input); } return $this->cache_result[$input]; }
-- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.dev (#31686) next »