Skip to content

Instantly share code, notes, and snippets.

@bbatsche
Last active August 29, 2015 14:06
Show Gist options
  • Save bbatsche/4c9595c95d5e6efa765c to your computer and use it in GitHub Desktop.
Save bbatsche/4c9595c95d5e6efa765c to your computer and use it in GitHub Desktop.
Student Class Example
<?php
class Student
{
public $firstName;
public $lastName;
public $cohort;
public $classStart;
public function __construct($firstName, $lastName, $cohort)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->assignCohort($cohort);
}
public function sayHello()
{
return "Hello {$this->firstName} {$this->lastName}";
}
public function assignCohort($classNum)
{
switch($classNum) {
case 1:
$this->cohort = 'Arches';
$this->classStart = new DateTime('2014-02-04');
break;
case 2:
$this->cohort = 'Badlands';
$this->classStart = new DateTime('2014-05-06');
break;
case 3:
$this->cohort = 'Carlsbad';
$this->classStart = new DateTime('2014-08-12');
break;
case 4:
$this->cohort = 'Denali';
$this->classStart = new DateTime('2014-09-30');
break;
case 5:
$this->cohort = 'Everglades';
break;
default:
echo "I don't know anything about that cohort\n";
return false;
}
}
}
$adam = new Student("Adam", "Vega", 3);
$travis = new Student("Travis", "Meyer", 1);
$greg = new Student("Greg", "Vallejo", 2);
$mary = new Student("Mary", "Reyes", 3);
echo $adam->firstName;
echo $travis->sayHello() . PHP_EOL;
echo $greg->sayHello() . PHP_EOL;
echo $mary->sayHello() . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment