I am a 2nd Year IT student just started with OOP in PHP and i'm really struggling to get the hang of it, I have been coding in a procedural way for years so please understand making the switch to OOP is extremely challenging, and I am yet to see the benefit of it, anyway just had to get that of my chest.
According to the above question I came above with the above code,, which I tweaked to infinity, my prescribed book is also not very helpful
CODE
class Registration{
private $user_type;
private $user_name;
function __construct($user_type, $user_name){
$this->user_type=$user_type;
$this->user_name=$user_name;
}//constructor
function setUser($user_type, $user_name){
if($user_type == "admin"){
$user_name = "Peter";
$msg = "Hi administrator ".$user_name;
}
else if($user_type="member"){
$user_name = "Ntubele123!";
$msg = "Hi member ".$user_name;
}
}//function
function getUser(){
return $this->user_type;
}//function getter
}//class
$userInfo = new Registration($user_type, $user_name);
$user = $userInfo->setUser("admin", "Peter");
$user = $userInfo->getUser();
MY QUESTIONS
- I suspect a lot is wrong with the above code, if someone could be kind enough to let me know where I am going wrong and what I should consider changing, keeping beginner friendly in mind, it would be greatly appreciated.
ERROR
Undefined variable user_type & user_name




$userInfo = new ...you need to create the$user_typeand$user_namevariables you're passing tonew Registration($user_type, $user_name..$user_type = $user_name = '';should doadminon screen when initializing the object asnew Registration("admin", "Peter")aaaarrrrrgggghhhhsetUser, which is supposed to set the user to the name given in the argument, but just displays a message.