gish Posted December 8, 2008 Share Posted December 8, 2008 Hi everyone, I need some direction to make sure my oop is correct. Inside the class i have the following functions. But the function random_class has to make a choice from a session variable. What I want to know is it alright to call the session variable directly or do I do it through the object call in the script if so how do I do it correctly? class random { private $correction_outcome; private $random_post; private $answer_string; private $Name; function __construct($random_post) { $this->random_outcome = $random_post; } public function random_class ($random_post){ //this is a will setup a cass choice so that it can choose a function $Name = $_SESSION['form_value']; //this needs to be a session switch($Name) { case "Jim": random_au(); break; case "Linda": random_su(); break; case "Bob": random_mu(); break; default: print "I'm broken and I don't know why\n"; } } public function random_checked() { return $this->random_outcome; } } the object call is this, $random_post = $_POST['form_value']; $random_object = new random($random_post); $random_object ->random_class($random_post); echo $random_object->random_checked(); If you see anything else that is wrong do tell me oo is still very new =) Link to comment https://forums.phpfreaks.com/topic/136131-oop-calling-post_variable/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 How you have it is fine, since SESSION is a global variable. Link to comment https://forums.phpfreaks.com/topic/136131-oop-calling-post_variable/#findComment-709927 Share on other sites More sharing options...
gish Posted December 8, 2008 Author Share Posted December 8, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/136131-oop-calling-post_variable/#findComment-709941 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.