I’ve got the following issue
class class_name {
function b() {
// do something
}
function c() {
function a() {
// call function b();
}
}
}
When I call function as usual: $this->b(); I get this error: Using $this when not in object context in C:…
function b() is declared as public
any thoughts?
I’ll appreciate any help
Thanks
The function
a()is declared inside methodc().Example using a function inside a method (not recommended)
The reason why your original code wasn’t working is because of scope of variables.
$thisis only available within the instance of the class. The functiona()is not longer part of it so the only way to solve the problem is to pass the instance as a variable to the class.