keeB Posted July 17, 2007 Share Posted July 17, 2007 <?php /* object checks to see if yahoo user is logged in or out */ /** * @author: nick stinemates */ class yahoo { private $name; private $YAHOO_URL = "http://216.155.194.208/online?u="; function yahoo($name) { $this->setName($name); } public function setName($name) { $this->name = $name; } public function check() { if(!isset($this->name)) { throw new Exception("choose a name to check, dumbass"); } $x = file_get_contents($this->YAHOO_URL . $this->name); if(strlen($x) == 140) return "online"; return "not online"; } } $y = new yahoo("nickstinemates2"); print $y->check(); ?> I was bored at work so I wrote this. Maybe not the best example of OO principals, but these are they types of things I wrote to learn how to program. Hope it's helpful to someone Link to comment https://forums.phpfreaks.com/topic/60304-simple-oo-example-how-to-check-if-a-yahoo-user-is-online/ Share on other sites More sharing options...
Jenk Posted July 17, 2007 Share Posted July 17, 2007 Criticism: check() should return boolean. setName() is not necessary when all you are doing is assign whatever value is sent to it. No type checking, no value validating, no nothing. Link to comment https://forums.phpfreaks.com/topic/60304-simple-oo-example-how-to-check-if-a-yahoo-user-is-online/#findComment-300408 Share on other sites More sharing options...
keeB Posted July 18, 2007 Author Share Posted July 18, 2007 I am used to developing setter/getter methods apart of my C++/Java endeavors. check() returned the image of the URL originally, but I quickly added the string when posting this, didn't even think of using a boolean (all i did was change the return values) Appreciate the criticism, though! Link to comment https://forums.phpfreaks.com/topic/60304-simple-oo-example-how-to-check-if-a-yahoo-user-is-online/#findComment-300791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.