prime Posted November 24, 2008 Share Posted November 24, 2008 Hi I am trying to work out how to call another function from inside the same class, I have had a look around and can't seem to find an answer, thank you I have the code below... I'm trying to access the browserMake funtion from inside the browserModel function, is this possible? <?php class agentCheck { function browserMake() { //determine the users browser $browser_detect = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/SlimBrowser/", "$browser_detect")) { return "Slim Browser"; } elseif(preg_match("/Opera/", "$browser_detect")) { return "Opera"; } elseif(preg_match("/MSIE/", "$browser_detect")) { return "Internet Explorer"; } elseif(preg_match("/Firefox/", "$browser_detect")) { return "Firefox"; } elseif(preg_match("/Chrome/", "$browser_detect")) { return "Chrome"; } elseif(preg_match("/Safari/", "$browser_detect")) { return "Safari"; } elseif(preg_match("/Konqueror/", "$browser_detect")) { return "Konqueror"; } elseif(preg_match("/Minefield/", "$browser_detect")) { return "Minefield"; } elseif(preg_match("/K-Meleon/", "$browser_detect")) { return "K-Meleon"; } elseif(preg_match("/Mozilla/", "$browser_detect")) { return "Mozilla"; } else { return "undefined"; } } function browserModel() { $browser_detect = $_SERVER['HTTP_USER_AGENT']; $browsers_make = browserMake(); return "$browsers_make"; } } $lets = new agentCheck; $browser = $lets->browserModel(); ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 $browsers_make = $this->browserMake(); or if the class is static $browsers_make = self::browserMake(); Quote Link to comment Share on other sites More sharing options...
prime Posted November 24, 2008 Author Share Posted November 24, 2008 Thx a lot :-) I know this is basic stuff, I've been doing php for quite a while now and but some dang reason I am having problem with oop lol I can see how this is going to save a huge amount of work though Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 It took me several years just to understand why OOP is useful Quote Link to comment Share on other sites More sharing options...
prime Posted November 24, 2008 Author Share Posted November 24, 2008 I understood the principle of it from when I started, about 3 years ago, but even once I learn most everything else I just kept putting off learning it... Every time I had to rewrite code or modify existing stuff to fit in I had that niggle in my mind telling me I should learn OOP to save time. Though I guess I still have to deal with polymorphisation, whatever that is.... Anyhow back I'm off back to my silly little browser model and make script to learn this stuff.... I've always hated following set examples you can't experiment as easy :-) Thx again :-) Quote Link to comment 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.