1

For the sake of the thread I have only 2 PHP classes, one for the Database and one for Users in my database.

When running the executing the code in my Users class a PHP notice is displayed on my browser stating..

Notice: Undefined property: Database::$escape in /my/directory/user.class.php on line x

In my Users class I have the following code:

$Database = new Database();
$submitData = array_map($Database->escape, $submitData);
$result = $Database->query("SELECT user_id FROM users WHERE email_address = " . $Database->quote($formData['email_address']));

In my Database class I have the following:

class Database { 
    private $db = array();
    private $connection;
    public $result;      

    public function escape($data) {
        return mysqli_real_escape_string($this->connection, $data);
    }   
...
Grant
  • 2,413
  • 2
  • 30
  • 41
InvalidSyntax
  • 9,131
  • 20
  • 80
  • 127

3 Answers3

1

Inproper callback, correct callback:

$submitData = array_map(array($Database, "escape"), $submitData);
ziollek
  • 1,973
  • 1
  • 12
  • 10
0

Try to give your Database instance another name, i think, when you want to use

$Database->escape

, php refers to

Database::$escape

, which is a static variable of the class Database, and such is not defined.

Sirac
  • 693
  • 4
  • 18
0

In your code you have array_map of $Database-> escape which searches for that property and throws the error. You should have a callable function's name like "escape" or some other function.

Emi
  • 1,018
  • 9
  • 13