Reputation: 3205
I have a class with few methods like this..
class ClassA
{
public functon funcA(arguments) : bool
{
// return true or false
}
public functon funcB(arguments) : bool
{
// return true or false
}
private function ifFalse(){ // do something }
}
What i want to do is call ifFalse()
method automatically when funcA()
or funcB()
are called and they return false.
How can I achive this? I am using php 7 by the way.
Upvotes: 0
Views: 50
Reputation: 64657
You can just call the function inside the other function:
$ret = false;
// return true or false
if (!$ret) $this->ifFalse();
return $ret;
If you want it more "magic", you could do:
public function __call($name, $arguments)
{
switch($name) {
case 'funcA':
case 'funcB':
$value = $this->$name(...$arguments);
if (!$value) $this->ifFalse();
return $value;
break;
}
}
private function funcA(arguments) : bool
{
// return true or false
}
private function funcB(arguments) : bool
{
// return true or false
}
Upvotes: 1