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); } ... 
2
  • use __set() and __get() magic methods to avoid this error !! Commented Feb 25, 2014 at 18:31
  • ah escape() is a method and u r trying to access as member variable Commented Feb 25, 2014 at 18:32

3 Answers 3

1

Inproper callback, correct callback:

$submitData = array_map(array($Database, "escape"), $submitData); 
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.