This question is not similar to the regarded questions. This question meant by a weird result of a PHP anonymous function. The regarding of Yii here is just for showing the context in which the anonymous function has been involved.
I decided to use PHP anonymous function to format an attribute value in the DetailView Widget in Yii2 application as follows:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'DatabaseID',
'Prod:ntext',
'desc:ntext',
[
'label' => Yii::t('app','review'),
'value' => function(){return 'hi';}, //Just for simplification the issue explanation. However, it is the actual code that generates the error.
],
],
]) ?>
I have got the following error which telling that the anonymous function does not return a string:
htmlspecialchars() expects parameter 1 to be string, object given
I wonder, why does the anonymous function return an object? As shown in the code sample, it should only return a simple string hi
!
I have read the PHP documentation about Anonymous functions but I could not able to find anything regarding this issue.