I’m using PHP here, and I have two classes. Can I call a function from one class in the other one. For example:
class A
{
function a_func()
{
echo "A function";
}
}
$a = new A();
class B
{
function b_func()
{
$a->a_func(); // This is the thing I'm stuck with.
}
}
I hope I’ve made myself clear here. I had a look on Google, but I don’t know what this is called so I came up with nothing. Thanks for any help.
You have 2 workarounds:
1) If your a_func doesn’t need an instance (seems it’s the case), you can make the function static and call it from the second class
2) 1) If your a_func needs an instance, you’re forced to create one: