A concise conditional method calling in PHP using variables for method names

A very naive yet effective approach on metaprogramming that helps you dynamically call the right method in a very concise manner.

$method = $user instance of User ? 'save' : 'saveMany';


The example is an excerpt from a dummy Laravel app.

30 Sep 2020