# help request: php array

- Thread: https://externals.io/message/4719
- Original archive: https://news-web.php.net/php.internals/4719
- Started by netcat on 2003-10-07T12:39:29+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4719 — netcat — 2003-10-07T12:39:29+00:00

URL: https://externals.io/message/4719#4719

Hi internals.

After looking at "Zend/zend_hash.h" e.t.c and haven't
realizing how should i do that,i'm asking for your help.
It should be really simple for you ....

Have the following function:
it should recursively convert data from rep_XXX to php data
It does that for string and numbers for now.
It's time to ad an array and hash.
The question is near "???".
(and another one - how this would look like for
adding hash elements (excluding the rep_XXX stuff of course))

int rep_data_converter(repv in,zval *return_value) {
    if(rep_STRINGP(in)) {
        //printf("REP Will return string\n");
        RETVAL_STRING (rep_STR(in),1);
        return 1;
    }
    if(rep_INTP(in)) {
        RETURN_LONG (rep_INT(in));
        return 1;
    }
    if(rep_LONG_INTP(in)) {
        RETURN_LONG (rep_LONG_INT(in));
        return 1;
    }
    // hadle array
    if(rep_CONSP(in)) {
        zval php_array;
        //zend_hash_init(&php_array,100,
        repv i,t;
        for(i=in;i!=Qnil;i=rep_CDR(i)) {
            printf("REP FWD to next element\n");
            rep_data_converter(rep_CAR(i),&t);
            /* ??? add t to array php_array */
        }
    }
                                                                                                

    RETVAL_STRING("REP: Unsupported type yet\n",1);
    return 0;
}

Thanks in advance.

-- 
NetCat



--------------------------------------------------
FREE 10MB Email + Antivirus + POP3 + more...
Get it at http://www.doal.co.il:81/free/?c=antivirus

---

## #4722 — Wez Furlong — 2003-10-07T12:46:24+00:00

URL: https://externals.io/message/4719#4722 · In reply to: #4719

Try something like this:

if (rep_CONSP(in)) {
    array_init(return_value); /* sets it up as an array */

   for (i = in; i != Qnil; i = rep_CDR(i)) {
      zval *tmp;

      MAKE_STD_ZVAL(tmp);
      rep_data_converter(rep_CAR(i), tmp);
      add_next_index_zval(return_value, tmp); /* equivalent to $ret[] = $tmp
*/
   }
}


>     if(rep_CONSP(in)) {
>         zval php_array;
>         //zend_hash_init(&php_array,100,
>         repv i,t;
>         for(i=in;i!=Qnil;i=rep_CDR(i)) {
>             printf("REP FWD to next element\n");
>             rep_data_converter(rep_CAR(i),&t);
>             /* ??? add t to array php_array */
>         }
>     }

---

## #4723 — netcat — 2003-10-07T13:09:24+00:00

URL: https://externals.io/message/4719#4723 · In reply to: #4722

Wez Furlong wrote:

>Try something like this:
>
>if (rep_CONSP(in)) {
>    array_init(return_value); /* sets it up as an array */
>
>   for (i = in; i != Qnil; i = rep_CDR(i)) {
>      zval *tmp;
>
>      MAKE_STD_ZVAL(tmp);
>      rep_data_converter(rep_CAR(i), tmp);
>      add_next_index_zval(return_value, tmp); /* equivalent to $ret[] = $tmp
>*/
>   }
>}
>
>
>  
>
> > […]
>
>
>
>  
>
I guess it almost works :

    if(rep_CONSP(in)) {
        repv i;
        for(i=in;i!=Qnil;i=rep_CDR(i)) {
            zval *t;
            MAKE_STD_ZVAL(t);
            printf("REP FWD to next element PT1\n");
            rep_data_converter(rep_CAR(i),t);
            printf("REP FWD to next element PT2\n");
            add_next_index_zval(return_value, t);
            printf("REP FWD to next element PT3\n");
            /* ??? add t to array() */
        }
    }

---8<--- 
                                                                                              

REP FWD to next element PT1
REP FWD to next element PT2
rep: received fatal signal: Segmentation fault
 
struct debug_buf common:
 
Backtrace in `fatal_signal_handler':
        <(null)+1107463240>
        <add_next_index_zval+28>
        <rep_data_converter+215>
        <zif_rep_eval+201>
        <execute+7234>
        <zend_execute_scripts+107>
        <php_execute_script+316>
        <main+1629>
 
Lisp backtrace:
 
Segmentation fault
---8<---

Is that rep's or php's problem?
May be t should be duplicated?
If yes, how?

-- 
NetCat



------------------------------------------------------
SPAM-Free 10mb Free email + Antivirus + POP3 + more...
Get it at http://www.doal.co.il:81/free/?c=all-spam

---

## #4724 — Wez Furlong — 2003-10-07T13:18:50+00:00

URL: https://externals.io/message/4719#4724 · In reply to: #4723

That backtrace isn't useful (running windows?)
Try a debug build, under unix if you have access to it.

Chances are that it is your code that is at fault :-)

--Wez.

> Backtrace in `fatal_signal_handler':
>         <(null)+1107463240>
>         <add_next_index_zval+28>
>         <rep_data_converter+215>
>         <zif_rep_eval+201>
>         <execute+7234>
>         <zend_execute_scripts+107>
>         <php_execute_script+316>
>         <main+1629>
>  
> Lisp backtrace:
>  
> Segmentation fault
> ---8<---
> 
> Is that rep's or php's problem?
> May be t should be duplicated?
> If yes, how?

---

## #4726 — netcat — 2003-10-07T13:33:16+00:00

URL: https://externals.io/message/4719#4726 · In reply to: #4724

Wez Furlong wrote:

>That backtrace isn't useful (running windows?)
>  
>
Yuck... never... windows cannot (must not) live outside VmWare :)

>Try a debug build, under unix if you have access to it.
>  
>
Will look for that. How fast it became not nice to me ....

>Chances are that it is your code that is at fault :-)
>  
>
It's 99.9%. The question should be rephrased:
I work wrong with PHP code or
I work wrong with REP code ?

Thanks a lot.

>--Wez.
>
>  
>
> > […]
>
>  
>


-- 
NetCat



---------------------------------------------------
FREE 10MB Email + AntiSpam + POP3 + more.
Get it at http://www.doal.co.il:81/free/?c=antispam

---

## #4732 — netcat — 2003-10-07T14:41:17+00:00

URL: https://externals.io/message/4719#4732 · In reply to: #4724

Wez Furlong wrote:

>That backtrace isn't useful (running windows?)
>Try a debug build, under unix if you have access to it.
>
>Chances are that it is your code that is at fault :-)
>  
>
Yep. It looked strange to me adding items to zval without even mentioning
it's array. So I looked in other places ....
array_init(return_value);
solved the problem.
Than i looked back into your letter.
I just missed this one in your letter,sorry....
Thanks again.

>--Wez.
>
>  
>
> > […]
>
>  
>


-- 
NetCat



---------------------------------------------------
FREE 10MB Email + AntiSpam + POP3 + more.
Get it at http://www.doal.co.il:81/free/?c=antispam
