3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getGrandParentClass($object, $level = NULL) { $gp = $object = get_class($object); $isNull = is_null($level); $j = 0; while(get_parent_class($gp) && ($isNull || $level > $j)) { $gp = get_parent_class($gp); $j++; if(!get_parent_class($gp) && !$isNull && $level > $j) return false; } return $gp == $object ? false : $gp; } class A {} class B extends A {} class C extends B {} class D extends C {} var_dump(getGrandParentClass(new A())); // false var_dump(getGrandParentClass(new D(), NaN));
Output for 4.3.0 - 7.1.0
bool(false) Notice: Use of undefined constant NaN - assumed 'NaN' in /in/QiJkC on line 28 bool(false)