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(), []);
Output for 5.4.0 - 5.4.22
Parse error: syntax error, unexpected ';' in /in/4kYNA on line 28
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/4kYNA on line 28
Process exited with code 255.