Using the instanceof Operator : instanceof « Language Basics « PHP






Using the instanceof Operator

 
<?php
     class Math {
          public function add($op1, $op2) {
               if(($op1 instanceof Float) && ($op2 instanceof Float)) {
                    return $op1->getFloat() + $op2->getFloat();
               } else {
                    echo "Must pass two Floats!\n";
               }
          }
     }
?>
  
  








Related examples in the same category

1.Difference between instanceof and is_subclass_of( )