Accessing values in associative arrays within C code?
| From: | chrisv at b0rked dot dhs dot org | Date: | Thu, 06 Jul 2000 04:11:41 +0000 |
| Subject: | Accessing values in associative arrays within C code? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-23657@lists.php.net to get a copy of this message | ||
I'm having a minor problem accessing values in a single associative array
which is passed into a function I am writing. It works, for the most part,
until I attempt to convert the 'zval *' pointers to the type I need.
The offending code looks like this:
%%%%%
HashTable *ht;
zval *l_onoff;
zval *l_linger;
convert_to_array_ex(optval);
ht = HASH_OF(*optval);
if (zend_hash_find(ht, "l_onoff", strlen("l_onoff") + 1,
(void **) &l_onoff) == FAILURE) {
zend_error(E_ERROR, "No key \"l_onoff\" passed in optval");
}
if (zend_hash_find(ht, "l_linger", strlen("l_linger") + 1,
(void **) &l_linger) == FAILURE) {
zend_error(E_ERROR, "No key \"l_linger\" passed in optval");
}
/* here are the offending lines of code */
convert_to_long(l_onoff);
convert_to_long(l_linger);
/* ------------------------------------ */
lv.l_onoff = ZVAL(&l_onoff, lval);
lv.l_linger = ZVAL(&l_linger, lval);
optlen = sizeof(lv);
ret = setsockopt(ZVAL(fd, lval), ZVAL(level, lval), ZVAL(optname, lval),
&lv, optlen);
%%%%%
Upon calling the function in PHP:
$optval["l_onoff"] = 0;
$optval["l_linger"] = 100;
$ret = setsockopt($fd, SOL_SOCKET, SO_LINGER, $optval);
PHP spits out the error:
<br>
<b>Warning</b>: Cannot convert to ordinal value in <b>sockets.php</b> on
line <b>26</b><br>
Can anyone help with this?
Chris