Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error, unexpected T_RETURN, expecting T_FUNCTION oop php [closed]

Im receiving an error as stated above. Its referring to my return statement. Any one got any clues on this?! Thankful for all help! Regards!

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;                                          
like image 471
Tim Avatar asked Sep 08 '10 12:09

Tim


2 Answers

Your return statement should come before the last closing brace.

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

        return $posts;                                          
    }
like image 112
BoltClock Avatar answered Nov 17 '22 21:11

BoltClock


Your return statement needs to be inside the function getPosts(). Currently it is outside or you have one } on the wrong line.

like image 3
joschi Avatar answered Nov 17 '22 20:11

joschi