Question: I have an array and want to apply `MySQLi->real_escape_string` on every member of the array through `array_walk` but this is not working:

```
array_walk($array, '$mysqli->real_escape_string');

```

It gives this error:

> 
> Warning: array\_walk() expects parameter 2 to be a valid callback, function '$mysqli->real\_escape\_string' not found or invalid function name in C:\wamp\www\ts.php on line 69
> 
> 
> 

`$mysqli` is a valid object and works fine if I do `$mysqli->real_escape_string('anything')` on anything else.

**My Question:** Is it not possible to pass object's functions as callback ? Or am I doing something wrong.

---

**IMPORTANT:** I know I can create my own callback function and implement $mysqli->real\_escape\_string in it *BUT* I want to know is it not possible to use callback as an object's function ?

Answer: 
As you can read on [php callback](http://php.net/manual/en/language.pseudo-types.php) page, you shall use:

```
# produces an error
array_walk($array, array($msqli, 'real_escape_string'));
array_map($array, array($msqli, 'real_escape_string'));

```
I found [this post](https://www.php.net/manual/en/function.array-walk.php#115622) to be quite useful when figuring out how to get `array_walk()` to work in methods within a class. Adding it to this thread in case it helps others out.