Skip to content

Instantly share code, notes, and snippets.

@gmanricks
Created April 14, 2013 14:24
Show Gist options
  • Save gmanricks/5382924 to your computer and use it in GitHub Desktop.
Save gmanricks/5382924 to your computer and use it in GitHub Desktop.
<?php
abstract class Shape
{
public function isShape()
{
return true;
}
}
class Square extends Shape
{
public function isSquare()
{
return true;
}
}
class Circle extends Shape
{
public function isSquare()
{
return false;
}
}
class Person
{
public function isSquare()
{
return false;
}
}
function checkSquare (Shape $sh) {
echo ($sh->isSquare()) ? "Yep" : "No";
}
checkSquare(new Square); // <- echoes "Yep"
//checkSquare(new Circle); // <- echoes "No"
//checkSquare(new Person); // <- type error
@bimaktuel
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment