Categories
Code Academy php unit Samuel

PHP Unit 10

Lesson 1:

// Create a Person class here:
class Person {

}

// And create a Person instance called $me here:
$me = new Person();

Lesson 2:

class Person {
public $isAlive = true;

function __construct($name) {
$this->name = $name;
}

public function dance() {
return "I'm dancing!";
}
}

$me = new Person("Shane");
if (is_a($me, "Person")) {
echo "I'm a person, ";
}
if (property_exists($me, "name")) {
echo "I have a name, ";
}
if (method_exists($me, "dance")) {
echo "and I know how to dance!";
}

Lesson 3:

class Shape {
public $hasSides = true;
}

class Square extends Shape {

}

$square = new Square();
// Add your code below!
if (property_exists($square, "hasSides")) {
echo "I have sides!";
}

lesson 4:

class Vehicle {
public function honk() {
return "HONK HONK!";
}
}
// Add your code below!

class Bicycle extends Vehicle {
public function honk() {
return "Beep beep!";
}
}

$bicycle = new Bicycle();
echo $bicycle->honk();

Lesson 5:

class Vehicle {
final public function honk() {
return "HONK HONK!";
}
}
// Add your code below!

class Bicycle extends Vehicle {
public function honk() {
return "Beep beep!";
}
}

$bicycle = new Bicycle();
echo $bicycle->honk();

Lesson 6:

class Person {

}
class Ninja extends Person {
// Add your code here...
const stealth = "MAXIMUM";

}
// ...and here!
echo Ninja::stealth;

lesson 7:

class King {
// Modify the code on line 10...
public static function proclaim() {
echo "A kingly proclamation!";
}
}
// ...and call the method below!
King::proclaim();

Lesson 8:

class Person {
public static function say() {
echo "Here are my thoughts!";
}
}

class Blogger extends Person {
const cats = 50;
static public $cats = "50";
}

Blogger::say();
echo Blogger::$cats;