Getting 'by reference' error using array_walk. How do I use it then?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lwoods

    #1

    Getting 'by reference' error using array_walk. How do I use it then?

    I have the following function:

    function clean_form( &$from_check ) {
    if(is_array($fr om_check)){
    array_walk(&$fr om_check,'clean _form');
    return;
    } else {
    $value = str_replace(arr ay("\r","\n","C ontent-Type:"),"",$fro m_check);
    }

    When I call this function I get the following warning:

    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 array_walk(). 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.

    In the PHP doc it shows referencing the array argument "by reference"; i.e.
    '&' , but the runtime says this is a "no go". Then how am I supposed to use
    array_walk?

    TIA,

    Larry Woods


  • Ewoud Dronkert

    #2
    Re: Getting 'by reference' error using array_walk. How do I use it then?

    lwoods wrote:[color=blue]
    > function clean_form( &$from_check ) {
    > array_walk(&$fr om_check,'clean _form');[/color]

    You need to define at least two parameters for the function you call with
    array_walk: array and item. So try: function clean_form(&$fr om_check,
    $value) { etc. }. That might take care of the error.

    --
    E. Dronkert

    Comment

    • Chung Leong

      #3
      Re: Getting 'by reference' error using array_walk. How do I use it then?

      lwoods wrote:[color=blue]
      > I have the following function:
      >
      > function clean_form( &$from_check ) {
      > if(is_array($fr om_check)){
      > array_walk(&$fr om_check,'clean _form');
      > return;
      > } else {
      > $value = str_replace(arr ay("\r","\n","C ontent-Type:"),"",$fro m_check);
      > }
      >
      > When I call this function I get the following warning:
      >
      > 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 array_walk(). 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.
      >
      > In the PHP doc it shows referencing the array argument "by reference"; i.e.
      > '&' , but the runtime says this is a "no go". Then how am I supposed to use
      > array_walk?
      >
      > TIA,[/color]

      array_walk() is declared to take a reference as the first argument, so
      you don't need to use & when you call the function. Just do
      array_walk($fro m_check,'clean_ form').

      The error message is bogus though. The array will still be passed by
      reference in this instance. Report it as a bug.

      Comment

      Working...