Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
677 views
in Technique[技术] by (71.8m points)

php - "return type has no value type specified in iterable type array." error does not reflect reality?

I am on php 7.4 and using phpstan action in github (latest) actions-x/phpstan@v1
I am getting the following error

return type has no value type specified in iterable type array

on the following method:

class A{
    /**
     * @return array
     */
    protected function get_next_bl():array{
        return [
            ["some string",[]]
        ];
    }
}

It is not clear to me what is wrong here.

question from:https://stackoverflow.com/questions/65832692/return-type-has-no-value-type-specified-in-iterable-type-array-error-does-not

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally I decided to install PHPStan locally to dig deeper.
When installed locally and run, You will get better error messages with fix suggestions.
PHPStan expects in the phpdoc that you tell it the possible types of the members of the array. Since the array in question is an array of arrays, the phpdoce syntax is:

@return array<array>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...