unemployment Posted October 18, 2011 Share Posted October 18, 2011 How can I call a public function inside of another public function? The get_primary_edge() says it's undefined, but it's just another public function in the class so shouldn't this work? public function get_dynamic_edge($uid) { $uid = (int)$uid; $sql = "( SELECT `users`.`id` FROM partners INNER JOIN `users` ON `partners`.`user_id` = `users`.`id` WHERE partners.friend_id = '${uid}' AND `approved` = 1 ) UNION ALL ( SELECT `users`.`id` FROM `partners` INNER JOIN `users` ON `partners`.`friend_id` = `users`.`id` WHERE `partners`.`user_id` = '${uid}' AND `approved` = 1 )"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; while (($row = mysql_fetch_assoc($result)) !== false) { $dynamic[$i] = array( 'uid' => $row['id'], 'score' => get_primary_edge($row['id']), ); $i++; } print_array($dynamic); } Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/ Share on other sites More sharing options...
ManiacDan Posted October 18, 2011 Share Posted October 18, 2011 $this->get_primary_edge() Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280199 Share on other sites More sharing options...
unemployment Posted October 18, 2011 Author Share Posted October 18, 2011 $this->get_primary_edge() That works thanks. What is the point of $this->? Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280201 Share on other sites More sharing options...
KevinM1 Posted October 18, 2011 Share Posted October 18, 2011 $this->get_primary_edge() That works thanks. What is the point of $this->? $this Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280227 Share on other sites More sharing options...
ManiacDan Posted October 18, 2011 Share Posted October 18, 2011 It's the critical variable in object oriented programming. It defines the current class scope and allows you access to the current class's methods and variables (and any inherited ones). I recommend reading that entire manual chapter that's linked above. Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280235 Share on other sites More sharing options...
unemployment Posted October 18, 2011 Author Share Posted October 18, 2011 It's the critical variable in object oriented programming. It defines the current class scope and allows you access to the current class's methods and variables (and any inherited ones). I recommend reading that entire manual chapter that's linked above. I will. I just made my first OOP class and I would really like to learn more about it, because I feel that it is the next step for me as a coder. Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280271 Share on other sites More sharing options...
trq Posted October 18, 2011 Share Posted October 18, 2011 It's the critical variable in object oriented programming. It defines the current class scope and allows you access to the current class's methods and variables (and any inherited ones). I recommend reading that entire manual chapter that's linked above. I will. I just made my first OOP class and I would really like to learn more about it, because I feel that it is the next step for me as a coder. Just because your using classes does not mean your coding in OOP. It's a first step, but it's not the entire picture. Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280356 Share on other sites More sharing options...
unemployment Posted October 19, 2011 Author Share Posted October 19, 2011 It's the critical variable in object oriented programming. It defines the current class scope and allows you access to the current class's methods and variables (and any inherited ones). I recommend reading that entire manual chapter that's linked above. I will. I just made my first OOP class and I would really like to learn more about it, because I feel that it is the next step for me as a coder. Just because your using classes does not mean your coding in OOP. It's a first step, but it's not the entire picture. Hmm Interesting. Care to explain? Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280385 Share on other sites More sharing options...
ManiacDan Posted October 19, 2011 Share Posted October 19, 2011 It's the critical variable in object oriented programming. It defines the current class scope and allows you access to the current class's methods and variables (and any inherited ones). I recommend reading that entire manual chapter that's linked above. I will. I just made my first OOP class and I would really like to learn more about it, because I feel that it is the next step for me as a coder. Just because your using classes does not mean your coding in OOP. It's a first step, but it's not the entire picture. Hmm Interesting. Care to explain? Well, mon frere, I wouldn't say this post was in French, n'est pas? Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280510 Share on other sites More sharing options...
KevinM1 Posted October 19, 2011 Share Posted October 19, 2011 It's the critical variable in object oriented programming. It defines the current class scope and allows you access to the current class's methods and variables (and any inherited ones). I recommend reading that entire manual chapter that's linked above. I will. I just made my first OOP class and I would really like to learn more about it, because I feel that it is the next step for me as a coder. Just because your using classes does not mean your coding in OOP. It's a first step, but it's not the entire picture. Hmm Interesting. Care to explain? Stuffing a bunch of thematically similar functions in a class isn't OOP. If it were that simple, then why would dozens of thick books exist on the subject? OOP is a completely different design methodology than procedural programming. It revolves around encapsulating both structures and behaviors, and dynamically using them/plugging them in/swapping them at run time. Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280513 Share on other sites More sharing options...
unemployment Posted October 19, 2011 Author Share Posted October 19, 2011 Sounds a lot more complicated than I realized. It's not just grouping functions and calling them in a specified group? Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280520 Share on other sites More sharing options...
ManiacDan Posted October 19, 2011 Share Posted October 19, 2011 Sounds a lot more complicated than I realized. It's not just grouping functions and calling them in a specified group? No. That's the first step. That's what makes some people make the jump from "include files" to "a math library," but a math library is not OOP. Changing pi() to math::pi() doesn't give you any benefit other than namespacing. Being able to say $user->save() and have it dynamically decide which database to save in and recursively save its child objects is a better example. Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280531 Share on other sites More sharing options...
unemployment Posted October 19, 2011 Author Share Posted October 19, 2011 Ahh yes... I see the big difference. Well... I guess I'm one step closer. Quote Link to comment https://forums.phpfreaks.com/topic/249321-call-public-function-in-another-public-function/#findComment-1280553 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.