1--TEST-- 2ReflectionClass::implementsInterface() 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8interface I1 {} 9class A implements I1 {} 10class B extends A {} 11 12interface I2 extends I1 {} 13class C implements I2 {} 14 15$classNames = array('A', 'B', 'C', 'I1', 'I2'); 16 17foreach ($classNames as $className) { 18 $rcs[$className] = new ReflectionClass($className); 19} 20 21foreach ($rcs as $childName => $child) { 22 foreach ($rcs as $parentName => $parent) { 23 echo "Does " . $childName . " implement " . $parentName . "? \n"; 24 echo " - Using object argument: "; 25 try { 26 var_dump($child->implementsInterface($parent)); 27 } catch (Exception $e) { 28 echo $e->getMessage() . "\n"; 29 } 30 echo " - Using string argument: "; 31 try { 32 var_dump($child->implementsInterface($parentName)); 33 } catch (Exception $e) { 34 echo $e->getMessage() . "\n"; 35 } 36 } 37} 38 39 40 41echo "\n\nTest bad arguments:\n"; 42try { 43 var_dump($rcs['A']->implementsInterface()); 44} catch (Exception $e) { 45 echo $e->getMessage() . "\n"; 46} 47try { 48 var_dump($rcs['A']->implementsInterface('C', 'C')); 49} catch (Exception $e) { 50 echo $e->getMessage() . "\n"; 51} 52try { 53 var_dump($rcs['A']->implementsInterface(null)); 54} catch (Exception $e) { 55 echo $e->getMessage() . "\n"; 56} 57try { 58 var_dump($rcs['A']->implementsInterface('ThisClassDoesNotExist')); 59} catch (Exception $e) { 60 echo $e->getMessage() . "\n"; 61} 62try { 63 var_dump($rcs['A']->implementsInterface(2)); 64} catch (Exception $e) { 65 echo $e->getMessage() . "\n"; 66} 67?> 68--EXPECTF-- 69Does A implement A? 70 - Using object argument: A is not an interface 71 - Using string argument: A is not an interface 72Does A implement B? 73 - Using object argument: B is not an interface 74 - Using string argument: B is not an interface 75Does A implement C? 76 - Using object argument: C is not an interface 77 - Using string argument: C is not an interface 78Does A implement I1? 79 - Using object argument: bool(true) 80 - Using string argument: bool(true) 81Does A implement I2? 82 - Using object argument: bool(false) 83 - Using string argument: bool(false) 84Does B implement A? 85 - Using object argument: A is not an interface 86 - Using string argument: A is not an interface 87Does B implement B? 88 - Using object argument: B is not an interface 89 - Using string argument: B is not an interface 90Does B implement C? 91 - Using object argument: C is not an interface 92 - Using string argument: C is not an interface 93Does B implement I1? 94 - Using object argument: bool(true) 95 - Using string argument: bool(true) 96Does B implement I2? 97 - Using object argument: bool(false) 98 - Using string argument: bool(false) 99Does C implement A? 100 - Using object argument: A is not an interface 101 - Using string argument: A is not an interface 102Does C implement B? 103 - Using object argument: B is not an interface 104 - Using string argument: B is not an interface 105Does C implement C? 106 - Using object argument: C is not an interface 107 - Using string argument: C is not an interface 108Does C implement I1? 109 - Using object argument: bool(true) 110 - Using string argument: bool(true) 111Does C implement I2? 112 - Using object argument: bool(true) 113 - Using string argument: bool(true) 114Does I1 implement A? 115 - Using object argument: A is not an interface 116 - Using string argument: A is not an interface 117Does I1 implement B? 118 - Using object argument: B is not an interface 119 - Using string argument: B is not an interface 120Does I1 implement C? 121 - Using object argument: C is not an interface 122 - Using string argument: C is not an interface 123Does I1 implement I1? 124 - Using object argument: bool(true) 125 - Using string argument: bool(true) 126Does I1 implement I2? 127 - Using object argument: bool(false) 128 - Using string argument: bool(false) 129Does I2 implement A? 130 - Using object argument: A is not an interface 131 - Using string argument: A is not an interface 132Does I2 implement B? 133 - Using object argument: B is not an interface 134 - Using string argument: B is not an interface 135Does I2 implement C? 136 - Using object argument: C is not an interface 137 - Using string argument: C is not an interface 138Does I2 implement I1? 139 - Using object argument: bool(true) 140 - Using string argument: bool(true) 141Does I2 implement I2? 142 - Using object argument: bool(true) 143 - Using string argument: bool(true) 144 145 146Test bad arguments: 147 148Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 0 given in %s on line 37 149NULL 150 151Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 2 given in %s on line 42 152NULL 153Parameter one must either be a string or a ReflectionClass object 154Interface ThisClassDoesNotExist does not exist 155Parameter one must either be a string or a ReflectionClass object 156