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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.