oikram Posted August 1, 2009 Share Posted August 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/ Share on other sites More sharing options...
GingerRobot Posted August 1, 2009 Share Posted August 1, 2009 Well are you actually assigning the return value of the method to anything? Or you should be able to pass the return value directly into the var_dump() function: var_dump($associacao_dao->listar($limit, $offset)); Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888380 Share on other sites More sharing options...
oikram Posted August 1, 2009 Author Share Posted August 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888393 Share on other sites More sharing options...
Daniel0 Posted August 1, 2009 Share Posted August 1, 2009 It would sound like you have to lookup the term "variable scope" in the manual. The $records variable only exists within the scope of that method. Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888395 Share on other sites More sharing options...
oikram Posted August 1, 2009 Author Share Posted August 1, 2009 Well are you actually assigning the return value of the method to anything? Do you mean: $blabla=$associacao_dao->listar($limit, $offset); Otherwise, we will get no return value at all... I don't believe this... :s Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888397 Share on other sites More sharing options...
Daniel0 Posted August 1, 2009 Share Posted August 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888398 Share on other sites More sharing options...
oikram Posted August 1, 2009 Author Share Posted August 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888436 Share on other sites More sharing options...
Daniel0 Posted August 1, 2009 Share Posted August 1, 2009 Well, maybe read Language Reference in the manual then. Quote Link to comment https://forums.phpfreaks.com/topic/168414-newbie-cant-access-a-method-return-value/#findComment-888440 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.