Skip to content

Instantly share code, notes, and snippets.

@Webbist-dev
Created November 19, 2014 14:16
Show Gist options
  • Save Webbist-dev/0b0f2472c90ccfe624a2 to your computer and use it in GitHub Desktop.
Save Webbist-dev/0b0f2472c90ccfe624a2 to your computer and use it in GitHub Desktop.
First php class and object usage
class Person {
public $teacher;
public $student;
public $age;
function displayStudentNameandTeacher() {
echo 'My Name is ' . $this->student . ' my teacher is ' . $this->teacher . '. My teachers age is ' . $this->getAge() . '.';
}
function setAge($var) {
$this->age = $var;
}
function getAge() {
return $this->age;
}
}
$obj1 = new Person();
$obj1->setAge(25);
$obj1->teacher = "Mrs Williams";
$obj1->student = "Alex Bennett";
$obj1->displayStudentNameandTeacher();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment