Last active
October 4, 2017 15:37
-
-
Save ruslanashaari/8f1426d288927e6a6aa367bc7999cca0 to your computer and use it in GitHub Desktop.
Using is_a or instanceof 1. is_a being a function takes an object as parameter 1, and a string (variable, constant, or literal) as parameter 2. So; ```is_a($object, $string); //only way to call it``` 2. instanceof takes an object as parameter 1, and can take a class name (variable), object instance (variable), or class identifier (class name wri…
This file contains 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 | |
class AreaCalculator { | |
public function calculate($shapes) | |
{ | |
//using is_a | |
if(is_a($shape, 'Square') // | |
{ | |
//bla bla bla | |
} | |
//using instanceof | |
if($shape instanceof Square) //Square is another class | |
{ | |
//bla bla bla | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment