It seems the self-closing tag (e.g. <x-component key="value" />) somehow will make the match[4] undefined in the callback function.
I tested the regex in preg_replace_callback() function and it seems the $match[4] should be empty rather than undefined in the case of using self-closing tag /> Not sure why it will throw an undefined error here.
As a temporary workaround, I have to add the ?? '' after $match[4] parameter to make it work for now.
$match[4] = $this->compileComponents( $match[4] ?? '');
Might need to investigate more for a better solution to fix the problem.
protected function compileComponents($value)
{
/**
* @param array $match
* [0]=full expression with @ and parenthesis
* [1]=Component name
* [2]=parameters
* [3]=...
* [4]=content
*
* @return string
*/
$callback = function($match) {
if(static::contains($match[0], 'x-')) {
$match[4] = $this->compileComponents( $match[4]);
}
$paramsCompiled = $this->parseParams($match[2]);
$str = "('components.".$match[1]."',".$paramsCompiled.")";
return self::compileComponent($str).$match[4].self::compileEndComponent();
};
return preg_replace_callback('/<x-([a-z0-9.-]+)(\s[^>]*)?(>((?:(?!<\/x-\1>).)*)<\/x-\1>|\/>)/ms', $callback, $value);
}
It seems the self-closing tag (e.g.
<x-component key="value" />) somehow will make thematch[4]undefined in the callback function.I tested the regex in
preg_replace_callback()function and it seems the$match[4]should be empty rather than undefined in the case of using self-closing tag/>Not sure why it will throw an undefined error here.As a temporary workaround, I have to add the
?? ''after$match[4]parameter to make it work for now.$match[4] = $this->compileComponents( $match[4] ?? '');Might need to investigate more for a better solution to fix the problem.