Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically call php object method based on test?

Can anyone tell me if it's possible to call a php object's method based on the success of a test? For example below...

Normal usage:

$obj = new obj;
$obj->call()
    ->successive()
    ->methods();

Running test to see if method should be called:

$obj = new obj;
$obj->call()
    ( if ($a) ? ->successive() : '')
    ->methods();

Is there any way to make the second example above work? Or another way to achieve the same result? Thanks.

like image 953
regan Avatar asked Jul 05 '26 00:07

regan


1 Answers

Perhaps?

$obj = new obj;
$temp = $obj->call();
if ($a) {
   $temp = $temp->successive();
}
$temp->methods();
like image 160
Marc B Avatar answered Jul 06 '26 14:07

Marc B