语法错误,意外的T_RETURN,期待T_FUNCTION oop php

Tim*_*Tim 4 php syntax-error

我收到如上所述的错误.它指的是我的退货声明.任何人都有这方面的线索?!感谢所有的帮助!问候!

public function getPosts() {
    $result = $this->db->query("SELECT * FROM posts");

    $posts = array();
    while($posts = $result->fetch_assoc()) {
        array_push($posts, new Post($post['id'], $post['created'], $post['author'], $post['title'], $post['body']));      
    }

} 
return $posts;                                          
Run Code Online (Sandbox Code Playgroud)

Bol*_*ock 12

你的return语句应该在最后一个结束括号之前.

        while($posts = $result->fetch_assoc()) {
            array_push($posts, new Post($post['id'], $post['created'], $post['author'], $post['title'], $post['body']));      
        }

        return $posts;                                          
    }
Run Code Online (Sandbox Code Playgroud)