Using the PHP users class you just created demonstrate how y

Using the PHP users class you just created, demonstrate how you would use construct a users object and then display of the field’s value using the getter methods. Be specific by provide the code.

Solution

class student
   {
public $name, $class, $roll; //Public variables; can be accessed from outside of the class
   private $grade; //Private variables; can not be accessed from outside of the class. Only accessed via getter or setter method
public function getDetails() //getter method
       {
echo \"Name: \" . $name;
       echo \"Class: \" . $class;
       echo \"Roll: \" . $roll;
       echo \"Grade: \" . $grade;
       }

   public function setDetails($foo) //setter method
       {
$this->grade = $foo; //set the value
return 0;
       }
   }

  
$stu = new student(); //creating a instance of the student class
$stu->setDetails(1); //calling setter method
$stu->getDetails(); //calling getter method

Using the PHP users class you just created, demonstrate how you would use construct a users object and then display of the field’s value using the getter method

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site