S
S
sajgak2011-09-17 22:18:32
PHP
sajgak, 2011-09-17 22:18:32

Newbie problems with zend API?

When working with zval in the function, there is no way to find the string index in the input array using the zend_hash_find function. Brief listing:

PHP_FUNCTION(test){
    HashTable *array1;
    zval **value1;
    char *key1 = "one";
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array1) == FAILURE) {
       RETURN_NULL();
    }
    if(zend_hash_find(array1, key1, strlen(key1), (void **)&value1) == FAILURE) {
       RETURN_BOOL(0);
    }
    RETURN_BOOL(1); 
 }

The function always returns false, even when the input array has the string key "one".
Thanks in advance for any insight

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
a_dobkin, 2011-09-19
@sajgak

Missed an error. instead of strlen(key1), you need strlen(key1) +1. Otherwise, the end-of-line character '\0' is ignored

K
Keyn Din, 2011-09-18
@Lure_of_Chaos

Try to localize the problem by selecting other functions with different parameters, try with PHP too

A
a_dobkin, 2011-09-19
@a_dobkin

The code is working, apparently in the function, in user space, incorrect data is being transferred
<?php
$arr = array('one' => 10, abc => 30, 'two' => 40 );
var_dump(test($arr)); // bool(true)
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question