Re: hash table guidance?
| From: | Gustavo Lopes | Date: | Wed, 02 Nov 2011 17:41:40 +0000 |
| Subject: | Re: hash table guidance? | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-8793@lists.php.net to get a copy of this message | ||
Em Wed, 02 Nov 2011 17:31:28 -0000, J. Adams <zardozrocks@gmail.com> escreveu:
I'm in the process of updating the AMFEXT extension. Specifically, I'm trying to serialize objects and arrays. I'm using the JSON extension as my guide and I'm a bit confused about how to handle PHP's hash table object. Can anyone direct me to a primer or introduction that explains how to deal with arrays/objects/hashtables?You can view the API in zend_hash.h: http://lxr.php.net/opengrok/xref/PHP_TRUNK/Zend/zend_hash.h If you want a high-level review and details of the most important functions (without having to go through the code), you can read Sara's book: http://www.amazon.com/Extending-Embedding-PHP-Sara-Golemon/dp/067232704X/ref=sr_1_1?s=books&ie=UTF8&qid=1320255383&sr=1-1
I would also appreciate recommendations or advice on how to accomplish the following: * determine if array keys are all numeric and contiguous or, if the array/object has associative keys or non-contiguous, detect that condition.No easy way, you have to go through the all the elements in the hash table in order to determine that. Also note that while for a hash table the keys 1 and "1" (string) are different things, userspace arrays are manipulated to interfaces that convert numeric strings to numbers when possible.
* detect if the current value to be serialized has been encountered before during the serialization of a particular object -- e.g., if a single array array or object appears more than once in a particular object via recursion or by referenced. I suspect this requires me to check the pointer fed to my function, but am unsure whether to dereference the pointer.For arrays there's no easy way; there's no concept of "same array". They can be or not be equal, but the identify the pointer comparison would give you would not be reliable since arrays, like other zvals, can be separated at any time. For objects, you can compare the ids (if you're interesting in identity, not equality).
[...]-- Gustavo Lopes