Skip to content

ide-helper: Exception: implode(): Argument #2 ($array) must be of type ?array, string given #272

Description

@PrintNow

当在模型中使用自定义访问器时,运行 php bin/hyperf.php ide-helper:model 会报错,示例代码:

class Customer extends Model
{
    protected string|null $table = 'customers';

    public function getNameAttribute(): string
    {
        return trim(join(' ', [$this->attributes['first_name'], $this->attributes['last_name']]));
    }
}

报错内容:

➜  xxx-hyperf git:(main) ✗ hyperf ide-helper:model       
Exception: implode(): Argument #2 ($array) must be of type ?array, string given
Could not analyze class App\Model\UserAdmin\Customer.

Trace:
#0 ~/work/xxx-hyperf/vendor/friendsofhyperf/ide-helper/src/Command/ModelCommand.php(686): implode('|', 'string')
#1 ~/work/xxx-hyperf/vendor/friendsofhyperf/ide-helper/src/Command/ModelCommand.php(652): FriendsOfHyperf\IdeHelper\Command\ModelCommand->getReturnTypeFromReflection(Object(ReflectionMethod))
#2 ~/work/xxx-hyperf/vendor/friendsofhyperf/ide-helper/src/Command/ModelCommand.php(375): FriendsOfHyperf\IdeHelper\Command\ModelCommand->getReturnType(Object(ReflectionMethod))
#3 ~/work/xxx-hyperf/vendor/friendsofhyperf/ide-helper/src/Command/ModelCommand.php(178): FriendsOfHyperf\IdeHelper\Command\ModelCommand->getPropertiesFromMethods(Object(App\Model\UserAdmin\Customer))
#4 ~/work/xxx-hyperf/vendor/friendsofhyperf/ide-helper/src/Command/ModelCommand.php(72): FriendsOfHyperf\IdeHelper\Command\ModelCommand->generateDocs(Array)
#5 ~/work/xxx-hyperf/vendor/hyperf/command/src/Command.php(428): FriendsOfHyperf\IdeHelper\Command\ModelCommand->handle()
#6 [internal function]: Hyperf\Command\Command->Hyperf\Command\{closure}()
#7 {main}

看代码后发现错误原因是:

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions