0

I have a PHP class which is supposed to return an array to where the object is instantiated. I have tried to figure out what the problem is but I can't seem to see it. Can anyone see where I have gone wrong here or point me in the right direction? Thanks

Here is the class (within a file called 'feeds.php.)

class updateFeed {
public function index() {
        $db = JFactory::getDBO();
        $query = "SELECT * FROM tweets";
        $db->setQuery($query);
        $result = $db->loadObject()
        if(strtotime($result->date_added) <= time() - 3200) {
            $this->updateTweets();
        }

        $query = "SELECT * FROM tweets ORDER BY tweet_date DESC LIMIT 0, 3";
        $db->setQuery($query);
        $results = $db->loadObjectList();

        $tweet_db = array();
        foreach($results as $result) {
            $tweet_db[] = array(
                'title'   =>   $result->title,
                'text'    =>   $result->text,
                'tweet_date'   =>   $result->tweet_date
            );
        }   
        return $tweet_db;

    }

And here is where the object is instantiated (in the index.php file):

include('feeds.php');
$tweet_dbs = new updateFeed;
print_r($tweet_dbs);

The print_r in the index file shows 'updateFeed Object ( ) '. Thanks in advance.

1
  • It simply should be print_r($tweet_dbs->index()); as you never call the class-method. Commented Oct 23, 2012 at 12:31

3 Answers 3

2

You are using your class wrong. You do not call index() method. Try this:

include('feeds.php');

// Create class instance
$instance = new updateFeed;

// Call your class instance's method
$tweet_dbs = $instance->index();

// Check result and have fun
print_r($tweet_dbs);
Sign up to request clarification or add additional context in comments.

Comments

0
include('feeds.php');
$tweet_dbs = new updateFeed;
$tweets = $tweet_dbs->index();
print_r($tweets);

You missed to call the index() function..

Comments

0

you need to call that method using object of the class.

replace

print_r($tweet_dbs) 

with

print_r($tweet_dbs->index()) 

4 Comments

@insertusernamehere: I dont get you .
I guess what you actually wanted to say is: "replace print_r($tweet_dbs) with print_r($tweet_dbs->index())".
nope .. print_r($tweet_dbs->index()) with print_r($tweet_dbs)
But you changed it anyhow. ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.