This might be a very noob question, but I can’t seem to find the answer anywhere. Is it possible to make your own function in a component and call it in the same component?
Example:
Class myComponent extends Component{
public function doSomething(){
doThis();
$b = $a + 2;
return $b;
}
function doThis(){
$a = 0;
}
}
You are mixing up several things here.
You can generally create object methods like this without problem. You have to call them as objects methods though:
Just calling
doThis()won’t magically create the variable$ain the calling scope. The variable will be created insidedoThisand will be contained there. And that’s a good thing. You’ll have to explicitlyreturnthe value from the method to make it available: