Created
April 14, 2013 14:24
-
-
Save gmanricks/5382924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bim aktüel