Here is what I am trying to do:


class dataConnection
{

/**
*  var definitions & constructor
*  other methods
*/

//then 

 function dbDataReady(&$data, $key = "")
{

    $data = trim($data);

    if (!get_magic_quotes_gpc())
   {
        if (function_exists("mysql_escape_string"))
        {

                $data = mysql_escape_string($data);

          } else {

                $data = addslashes($data);

          }

    } 
        return $data;

}


}

  /**
  * the above class is actually included via require_once()
  * and then instantiated (if not already) as this require / include
  * occurs on each page. I instanciate the calss like this:
  *
  * if(!is_object($_SESSION["dataSource"]))
  * {
  *    
* $_SESSION["dataSource"] = &new dataConnection; *
* $_SESSION["dataConn"] = $_SESSION["dataSource"]->dbConnect(); * * } else { * * $_SESSION["dataConn"] = $_SESSION["dataSource"]->dbConnect(); * * } * * Now I want to use the method dbDataReady() with * array_walk() */ array_walk($_POST, "don know what to put here?"); /* * when the method is a local function, all is golden * array_walk($_POST, "dbDataReady"); * but as a method, I can't seem to find a way to call the * class and method. * things like array_walk($_POST, '$_SESSION["dataSource"]->dbDataReady'); * will not work. */

What am I missing? Any ideas?

Kevin

    first of all, you dont need to return the $data in your function. that wouldnt do anything in your example.

    try these:

    array_walk($_POST, 'dataConnection->dbDataReady');

    or

    array_walk($_POST, 'dataConnection::dbDataReady');

    now your $_POST should be cured.

      Hey daarius,

      Thanks for the reply.

      I didn't write this function (dbDataReady) specifically for use with array_walk(), therefore the return $data is for use when calling dbDataReady() directly:

      $someValue = dbDataReady($someValue);

      The return has no effect on the results of array_walk().

      try these:

      array_walk($_POST, 'dataConnection->dbDataReady');

      or

      array_walk($_POST, 'dataConnection::dbDataReady');

      now your $_POST should be cured.

      These solutions will not work.

      dataConnection is instanciated previously and the object asigned to $_SESSION["dataSource"]:

      $dataSource = new dataConnection;
      
      $_SESSION["dataSource"] = $dataSource;
      
      //Which I suppose could be simply:
      
      
      $_SESSION["dataSource"] = new dataConnection;
      

      in any case the method of the calss has to be called like:

      $_SESSION["dataSource"]->dbDataReady();

      which is not a problem except when I try to use it with array_walk().

      i.e.

      array_walk($POST, '$SESSION["dataSource"]->dbDataReady');

      array_walk($POST, "\$SESSION[\"dataSource\"]->dbDataReady");

      and a host of other attempts will all produce the error:

      Warning: Unable to call dataConnection::dbDataReady() - function does not exist

      or

      Warning: Unable to call $_POST["dataSource"]->dbDataReady() - function does not exist

      or a variation there of based on the arg to array_walk().

      It would seem that no matter how I try supply the argument name for the method it is interpreted literally or as not as a string representing the name of the method. If that makes sense.

      So, how can I supply array_walk() with the function (class method) name in a way that it will be parsed?

      Kevin

        Write a Reply...