Perad Posted April 27, 2007 Share Posted April 27, 2007 If i have this it works and it echo's out the 2 wrong statements. class FilterPage { private $all; private $id; public function getpage() { if($this->all == "1") { echo "all right"; } else { echo "all wrong"; } if($this->id == "1") { echo "id right"; } else { echo "id wrong"; } echo "Nothing"; } } However i want to use $_GET as below but it just returns nothing. Does anyone know why this is? class FilterPage { private $all = $_GET['all']; private $id = $_GET['id']; public function getpage() { if($this->all == "1") { echo "all right"; } else { echo "all wrong"; } if($this->id == "1") { echo "id right"; } else { echo "id wrong"; } echo "Nothing"; } } Quote Link to comment https://forums.phpfreaks.com/topic/48918-why-doesnt-get-work-with-my-class/ Share on other sites More sharing options...
mjlogan Posted April 27, 2007 Share Posted April 27, 2007 <?php class FilterPage { private $all; private $id; public function getpage() { $this->all = $_GET['all']; $this->id = $_GET['id']; if($this->all == "1") { echo "all right"; } else { echo "all wrong"; } if($this->id == "1") { echo "id right"; } else { echo "id wrong"; } echo "Nothing"; } } $_temp = new FilterPage(); echo $_temp->getpage(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48918-why-doesnt-get-work-with-my-class/#findComment-239710 Share on other sites More sharing options...
wildteen88 Posted April 27, 2007 Share Posted April 27, 2007 Another way would to be to use a constructor: <?php class FilterPage { private $all; private $id; // this will get called automatically when the class is initiated. public function FilterPage() { $this->all = $_GET['all']; $this->id = $_GET['id']; } public function getpage() { if($this->all == 1) { echo "all right"; } else { echo "all wrong"; } if($this->id == 1) { echo "id right"; } else { echo "id wrong"; } echo "Nothing"; } } $_temp = new FilterPage(); echo $_temp->getpage(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48918-why-doesnt-get-work-with-my-class/#findComment-239962 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.