views:

116

answers:

2

Hi, 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;                                          
+5  A: 

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;                                          
    }
BoltClock
I don't talk to household devices that suddenly turn into Unicorns. That's *scary.*
Pekka
@Pekka: **fine!** :P
BoltClock
thanks for the quick answers. I found the answer just after I posted the question :) a bit to quick on my finger I reckon. Thanks!
Tim
@Pekka the potter get scared of unicorn!!! :P
OM The Eternity
A: 

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

joschi