Return 类型为数组但返回字符串

Return type is array but string returned

此声明中是否有任何错误请帮忙,我收到错误:-

我的代码

public function function(): array
{
    return $this->data['value'] ?? [];
}

我得到的错误是:- 函数应该 return 一个数组,但是字符串 returned.

试试这个简单的例子,你的函数声明是错误的:

<?php
    function test() {
       return $this->data['value'] ?? [];
    }

    $result = test();
?>