Jump to content

Newbie: can't access a method return value.


oikram

Recommended Posts

Hi all,

 

When I do this:

$associacao_dao->listar($limit, $offset);

 

I can var_dump the correct $limit.

I can var_dump the correct $offset.

 

I CAN'T access the object that I was hoping to get, called $records.

 

 

After this, I was hoping to do var_dump($records); and see the stdClass object.

 

Here is the listar method:

 

public function listar($limit=null, $offset=null) {
$query_str="SELECT * FROM associacao";

$stmt = $this->_dbh->prepare($query_str . ' LIMIT ?, ?');
$stmt->bindParam(1, $limit, PDO::PARAM_INT);
$stmt->bindParam(2, $offset, PDO::PARAM_INT);

$stmt->execute();

$records = $stmt->fetchAll(PDO::FETCH_OBJ);

return $records;		
}

 

 

 

Any help will be greatly appreciated.

 

 

Thanks a lot in advance,

Márcio

 

Thanks for the quick reply. I'm absolutely newbie so, sorry for any inconvenience. Please don't go away, I'm trying to solve this for hours. :s

 

When we do:

var_dump($associacao_dao->listar($limit, $offset));

 

It lists the object contents as expected.

 

 

I was thinking that:

When we have a function that returns something and then, later, we call that function, we will have access to that return "think" after the function or method has been called.

 

But it seems that it's not the case, since I want to use that returned object do iterate on a foreach but it keeps telling me that the variable $records is not defined.

 

Please advice...

Márcio

 

 

 

 

You must assign it to something or pass it on to something else. If you don't do anything with the return value it's sort of useless.

 

Go it. When I say I'm newbie, I REALLY mean it. But I get it. To get a value of a method that returns something, we need to grab that return "think" somehow, so that we can use it, case php will not automagicly do this for us. And we will prefer to have control over the all process.

 

 

Regards,

Márcio

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.