cobusbo Posted September 23, 2015 Share Posted September 23, 2015 Hi I got two functions and I want to use the 2nd function within the first function is this possible Function 1 class poll { public $db; public $tbl; public $pollvars; public $poll_view_html; public $poll_result_html; public $options; public $options_text; public $poll_question; public $form_forward; public $template_set; public $ip; public function __construct() { global $POLLTBL, $CLASS; $this->tbl = $POLLTBL; $this->poll_view_html = array(); $this->poll_result_html = array(); $this->options = array(); $this->options_text = array(); $this->poll_question = array(); $this->form_forward = basename($_SERVER['PHP_SELF']); $this->ip = getenv("REMOTE_ADDR"); $this->db = &$CLASS["db"]; $this->pollvars = $this->db->fetch_array($this->db->query("SELECT * FROM ".$this->tbl['poll_config'])); $this->template_set = "default"; if ($this->pollvars['result_order'] == "asc") { $this->pollvars['result_order'] = "ORDER BY votes ASC"; } elseif ($this->pollvars['result_order'] == "desc") { $this->pollvars['result_order'] = "ORDER BY votes DESC"; } else { $this->pollvars['result_order'] = ''; } } Function 2 function getUserIP() { $mxitidun = $_SERVER['HTTP_X_MXIT_DEVICE_ID']; $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; if($mxitidun != '') { $ip1 = $mxitidun; } elseif(filter_var($client, FILTER_VALIDATE_IP)) { $ip1 = $client; } elseif(filter_var($forward, FILTER_VALIDATE_IP)) { $ip1 = $forward; } else { $ip1 = $remote; } return $ip1; } I'm trying to Use the line in function 1 $this->ip = getenv("REMOTE_ADDR"); and replace getenv("REMOTE_ADDR"); with the function output value of Function 2 Quote Link to comment https://forums.phpfreaks.com/topic/298291-how-to-use-a-function-within-a-function/ Share on other sites More sharing options...
Solution Ch0cu3r Posted September 23, 2015 Solution Share Posted September 23, 2015 (edited) You would call your function like any other function $this->ip = getUserIP(); Or if getUserIP is a method for your poll class then it'll be $this->ip = $this->getUserIP(); Edited September 23, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/298291-how-to-use-a-function-within-a-function/#findComment-1521417 Share on other sites More sharing options...
cobusbo Posted September 23, 2015 Author Share Posted September 23, 2015 You would call your function like any other function $this->ip = getUserIP(); Or if getUserIP is a method for your poll class then it'll be $this->ip = $this->getUserIP(); Ah thank you I see I had the same function on both pages and got redeclare error so I fixed it Quote Link to comment https://forums.phpfreaks.com/topic/298291-how-to-use-a-function-within-a-function/#findComment-1521419 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.