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(), function(){}));
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
bool(false) Notice: Object of class Closure could not be converted to int in /in/HZZVC on line 9 Notice: Object of class Closure could not be converted to int in /in/HZZVC on line 9 string(1) "C"
Output for hhvm-3.12.0
bool(false) Notice: Object of class Closure$getGrandParentClass;1189800205$8e84b6944179f36d620696bb7443f7c$ could not be converted to int in /in/HZZVC on line 9 Notice: Object of class Closure$getGrandParentClass;1189800205$8e84b6944179f36d620696bb7443f7c$ could not be converted to int in /in/HZZVC on line 9 string(1) "C"
Output for hhvm-3.10.0
bool(false) Notice: Object of class Closure$getGrandParentClass;1189800205$c6f8bc52a989cf57dcf5139f517e6718$ could not be converted to int in /in/HZZVC on line 9 Notice: Object of class Closure$getGrandParentClass;1189800205$c6f8bc52a989cf57dcf5139f517e6718$ could not be converted to int in /in/HZZVC on line 9 string(1) "C"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/HZZVC on line 28
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/HZZVC on line 28
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/HZZVC on line 28
Process exited with code 255.