PHP type hinting in OOP http://stackoverflow.com/questions/17736541/object-type-hinting-in-php
class Song {
public $title;
public $lyrics;
}
function sing(Song $song){
echo "Singing the song called " .$song->title;
echo "<p>" . $ong->lyrics . "</p>";
}
$hit = new Song;
$hit->title = "Beat it!";
$hit->lyrics = "It doesn't matter who's wrong or right... just beat it!";
sing($hit); // would work just fine
/*
Type hinting means that whatever you pass must be an instance of (the same type as) the type you're hinting.
So, if you hint to Person only objects of that type will be accepted.
Now, let's say we have a class Poem:
*/
class Poem {
public $title;
public $lyrics;
}
$poem = new Poem;
$poem->title = "Look at the sea";
$poem->lyrics = "How blue, blue like the sky, in which we fly..."
echo sing($poem); // we will get an error because $poem is not the type of object we've hinted to when creating the function sing().