How can I access function b from within function a?
This is what I have so far, and I’m getting this error: PHP Fatal error: Call to undefined method a::b()
class test {
function a($x) {
switch($x)
{
case 'a'://Do something unrelated to class test2
break;
case 'b':
$this->b();
break;
}
}
}
class test2 extends test {
function b() {
echo 'This is what I need to access';
}
}
$example=new test();
$example2=new test2();
$example->a(b);
For background information – function a is a switch for requests sent via AJAX. Depending on the request, it calls a function to add a record to a database, edit it etc.
Thanks!
You have to define an abstract method b in the base class test (which makes this class abstract, so you cannot have instances of it) to call this method, otherwise the function b is not defined in this class, only in it’s subclass of which the base class knows nothing (and should not have to know anything).
Read up on inheritance.
Another thing: a and b are not defined, use quotes. (But this might be just lazyness in your example)