Skip to content

Instantly share code, notes, and snippets.

@ruslanashaari
Last active October 4, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruslanashaari/8f1426d288927e6a6aa367bc7999cca0 to your computer and use it in GitHub Desktop.
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…
<?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