confusion reading using zend_hash_exists()
| From: | Nathan Nobbe | Date: | Sun, 22 Feb 2009 18:50:35 +0000 |
| Subject: | confusion reading using zend_hash_exists() | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-6149@lists.php.net to get a copy of this message | ||
hi,
ive got a class Model, which has a protected instance value, $proxyMap,
which is an array. Model has ans instance method hasProxy(), which im
having trouble with. i read the proxyMap value from the instance, but then
when i try to search for a value im sure is in there, w/ zend_hash_exists()
it tells me its not there. i know im going wrong somewhare, but im
stummpted atm. heres the code,
PHP_METHOD(Model, hasProxy)
{
zval *this, *proxyMap, *proxyName;
char *rawProxyName;
int rawProxyNameLength;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&rawProxyName, &rawProxyNameLength) == FAILURE) {
return;
}
this = getThis();
proxyMap = zend_read_property(zend_get_class_entry(this), this,
"proxyMap", sizeof("proxyMap")-1, 1 TSRMLS_CC);
/// debugging
if(Z_TYPE_P(proxyMap) == IS_ARRAY) {
php_printf("proxyMap is an array\n");
php_printf("rawProxyName: %s\n", rawProxyName);
}
if(zend_hash_exists(Z_ARRVAL_P(proxyMap),
rawProxyName, rawProxyNameLength)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
heres the userspace test code (i dump out the Model instance before calling
hasProxy() so we can see its there)
<?php
$m = Model::getInstance();
$m->registerProxy(new MyProxy());
var_dump($m);
var_dump($m->hasProxy('testProxy'));
andl lastly, the output from the test script,
object(Model)#1 (1) {
["proxyMap:protected"]=>
array(1) {
["testProxy"]=>
object(MyProxy)#2 (0) {
}
}
}
proxyMap is an array
rawProxyName: testProxy
bool(false)
so, it looks like the proxyMap array has a value @ key "testProxy", and also
"testProxy" has been correctly recieved by hasProxy() as the key to search
for. proxyMap checks out to be an array, but for some reason the call to
zend_hash_exists() isnt working. my gut tells me its something to do w/
Z_ARRVAL_P(), but thats returning the *HashTable pointer from proxyMap -
that seems right.. any ideas why i cant find this hash?
tia,
-nathan