YsoL8
YsoL8

Reputation: 2214

PHP Classes - call one class function from another

I have a function in a class with this code:

$this -> userDb;
$error = $this -> error;
print_r($error);

userDb is another function in this class and error is generated by userDb. It always gives a non-empty array.

Why wouldn't I be able to get the value of $this -> error?

Upvotes: 1

Views: 1068

Answers (3)

Hameedullah Khan
Hameedullah Khan

Reputation: 346

First userDb is function but you aren't calling the function. You have to call userDb as

$this->userDb();

Upvotes: 1

BenM
BenM

Reputation: 53198

Without seeing the code for the userDb function, it's difficult to explain why the error is caused. However, if you're trying to call the function, you need to include the brackets in the function call:

$this->userDb();
print_r($this->error);

Upvotes: 0

Headshota
Headshota

Reputation: 21449

to call a method (function) you must use parentheses:

$this->userDb();

Upvotes: 0

Related Questions