Jump to content

[SOLVED] Calling another function in the same class


prime

Recommended Posts

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();
?>

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 :-)

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.