recursive function calling by reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephanie Le Gall

    recursive function calling by reference

    Hello,


    I'm using a recursive function to get an array of ID from a database passing
    the array by reference.

    I need this structure for the function because the database structure is
    like a tree and there is no limit of level.

    Here is the code :

    _______________ _______________ _______________ _______
    function remplir_tableau ($id, &$arrayOfAllEle m)
    {
    $arrayOfAllElem[] = $id;
    $req_ksup = mysql_query("se lect kinf_ksup,nume_ kard,soci_kard
    from kardex_superieu r
    left join kardex on id_kard=kinf_ks up
    where ksup_ksup='$id' ");

    while ($row = mysql_fetch_arr ay($req_ksup, MYSQL_NUM))
    {
    remplir_tableau ($row[0], &$arrayOfAllEle m);
    }
    }


    remplir_tableau ($id_kard, $TabKard);
    _______________ _______________ _______________ ________




    but if I don't change the php.ini file allow_call_time _pass_reference to
    true I have a message :

    Warning: Call-time pass-by-reference has been deprecated - argument passed
    by value; If you would like to pass it by reference, modify the declaration
    of [runtime function name](). If you would like to enable call-time
    pass-by-reference, you can set allow_call_time _pass_reference to true in
    your INI file. However, future versions may not support this any longer.


    I have the error message but the function seems to work anyway !


    Is there any way else to do that ? ... or to not have the message ?


    Thanks a lot for helping !



    Stéphanie


  • Janwillem Borleffs

    #2
    Re: recursive function calling by reference

    Stephanie Le Gall wrote:[color=blue]
    > I have the error message but the function seems to work anyway !
    >
    >
    > Is there any way else to do that ? ... or to not have the message ?
    >[/color]

    Change the recursive call to:

    function remplir_tableau ($id, &$arrayOfAllEle m)
    {
    .....
    remplir_tableau ($row[0], $arrayOfAllElem );
    }
    }



    JW

    Comment

    • Stephanie Le Gall

      #3
      Re: recursive function calling by reference

      Thanks a lot !!!!

      I've juste seen my error ... And I feel terrible sending a post like that
      !!!

      Stéphanie


      "Janwillem Borleffs" <jw@jwscripts.c om> a écrit dans le message de
      news:44339C69.2 050109@jwscript s.com...[color=blue]
      > Stephanie Le Gall wrote:[color=green]
      > > I have the error message but the function seems to work anyway !
      > >
      > >
      > > Is there any way else to do that ? ... or to not have the message ?
      > >[/color]
      >
      > Change the recursive call to:
      >
      > function remplir_tableau ($id, &$arrayOfAllEle m)
      > {
      > .....
      > remplir_tableau ($row[0], $arrayOfAllElem );
      > }
      > }
      >
      >
      >
      > JW
      >[/color]


      Comment

      • Chung Leong

        #4
        Re: recursive function calling by reference

        Stephanie Le Gall wrote:[color=blue]
        > Hello,
        >
        >
        > I'm using a recursive function to get an array of ID from a database passing
        > the array by reference.
        >
        > I need this structure for the function because the database structure is
        > like a tree and there is no limit of level.[/color]

        Just a suggestion. Retrieving a tree from the database in the manner
        you described can be expensive, since every nodes would trigger a
        separate query. Usually what I do in a situation like this is to add a
        column holding the id to the root of the tree, so that I could retrieve
        all the rows at once. Then I use a recursive function to build the
        tree.

        Comment

        Working...