How can recursion be utilized to extract object method calls with parameters from a template in PHP?

To extract object method calls with parameters from a template in PHP using recursion, we can parse the template content and look for patterns that match method calls with parameters. By recursively searching through the template content, we can identify and extract these method calls along with their parameters.

function extractMethodCalls($content) {
    $matches = [];
    preg_match_all('/\$\w+->\w+\((.*?)\)/', $content, $matches);

    $methodCalls = [];
    foreach ($matches[0] as $match) {
        $methodCalls[] = $match;
    }

    return $methodCalls;
}

$template = 'Hello, $obj->method("param1", "param2")! How are you?';
$methodCalls = extractMethodCalls($template);

print_r($methodCalls);