1--TEST-- 2ReflectionParameter::getClass(), getDeclaringClass(), getDeclaringFunction() 3--FILE-- 4<?php 5 6function test($nix, Array $ar, &$ref, stdClass $std, 7 NonExistingClass $na, stdClass &$opt = NULL, $def = "FooBar") 8{ 9} 10 11class test 12{ 13 function method($nix, Array $ar, &$ref, stdClass $std, 14 NonExistingClass $na, stdClass $opt = NULL, $def = "FooBar") 15 { 16 } 17} 18 19function check_params_decl_func($r, $f) 20{ 21 $c = $r->$f(); 22 $sep = $c instanceof ReflectionMethod ? $c->class . '::' : ''; 23 echo $f . ': ' . ($c ? $sep . $c->name : 'NULL') . "()\n"; 24} 25 26function check_params_decl_class($r, $f) 27{ 28 $c = $r->$f(); 29 echo $f . ': ' . ($c ? $c->name : 'NULL') . "\n"; 30} 31 32function check_params_func($r, $f) 33{ 34 echo $f . ': '; 35 $v = $r->$f(); 36 var_dump($v); 37} 38 39function check_params($r) 40{ 41 echo "#####" . ($r instanceof ReflectionMethod ? $r->class . '::' : '') . $r->name . "()#####\n"; 42 $i = 0; 43 foreach($r->getParameters() as $p) 44 { 45 echo "===" . $i . "===\n"; 46 $i++; 47 check_params_func($p, 'getName'); 48 check_params_func($p, 'isPassedByReference'); 49 try 50 { 51 check_params_decl_class($p, 'getClass'); 52 } 53 catch(ReflectionException $e) 54 { 55 echo $e->getMessage() . "\n"; 56 } 57 check_params_decl_class($p, 'getDeclaringClass'); 58// check_params_decl_func($p, 'getDeclaringFunction'); 59 check_params_func($p, 'isArray'); 60 check_params_func($p, 'allowsNull'); 61 check_params_func($p, 'isOptional'); 62 check_params_func($p, 'isDefaultValueAvailable'); 63 if ($p->isOptional()) 64 { 65 check_params_func($p, 'getDefaultValue'); 66 } 67 } 68} 69 70check_params(new ReflectionFunction('test')); 71 72check_params(new ReflectionMethod('test::method')); 73 74?> 75--EXPECTF-- 76#####test()##### 77===0=== 78getName: string(3) "nix" 79isPassedByReference: bool(false) 80 81Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 82getClass: NULL 83getDeclaringClass: NULL 84isArray: 85Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 86bool(false) 87allowsNull: bool(true) 88isOptional: bool(false) 89isDefaultValueAvailable: bool(false) 90===1=== 91getName: string(2) "ar" 92isPassedByReference: bool(false) 93 94Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 95getClass: NULL 96getDeclaringClass: NULL 97isArray: 98Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 99bool(true) 100allowsNull: bool(false) 101isOptional: bool(false) 102isDefaultValueAvailable: bool(false) 103===2=== 104getName: string(3) "ref" 105isPassedByReference: bool(true) 106 107Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 108getClass: NULL 109getDeclaringClass: NULL 110isArray: 111Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 112bool(false) 113allowsNull: bool(true) 114isOptional: bool(false) 115isDefaultValueAvailable: bool(false) 116===3=== 117getName: string(3) "std" 118isPassedByReference: bool(false) 119 120Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 121getClass: stdClass 122getDeclaringClass: NULL 123isArray: 124Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 125bool(false) 126allowsNull: bool(false) 127isOptional: bool(false) 128isDefaultValueAvailable: bool(false) 129===4=== 130getName: string(2) "na" 131isPassedByReference: bool(false) 132 133Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 134Class "NonExistingClass" does not exist 135getDeclaringClass: NULL 136isArray: 137Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 138bool(false) 139allowsNull: bool(false) 140isOptional: bool(false) 141isDefaultValueAvailable: bool(false) 142===5=== 143getName: string(3) "opt" 144isPassedByReference: bool(true) 145 146Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 147getClass: stdClass 148getDeclaringClass: NULL 149isArray: 150Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 151bool(false) 152allowsNull: bool(true) 153isOptional: bool(true) 154isDefaultValueAvailable: bool(true) 155getDefaultValue: NULL 156===6=== 157getName: string(3) "def" 158isPassedByReference: bool(false) 159 160Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 161getClass: NULL 162getDeclaringClass: NULL 163isArray: 164Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 165bool(false) 166allowsNull: bool(true) 167isOptional: bool(true) 168isDefaultValueAvailable: bool(true) 169getDefaultValue: string(6) "FooBar" 170#####test::method()##### 171===0=== 172getName: string(3) "nix" 173isPassedByReference: bool(false) 174 175Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 176getClass: NULL 177getDeclaringClass: test 178isArray: 179Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 180bool(false) 181allowsNull: bool(true) 182isOptional: bool(false) 183isDefaultValueAvailable: bool(false) 184===1=== 185getName: string(2) "ar" 186isPassedByReference: bool(false) 187 188Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 189getClass: NULL 190getDeclaringClass: test 191isArray: 192Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 193bool(true) 194allowsNull: bool(false) 195isOptional: bool(false) 196isDefaultValueAvailable: bool(false) 197===2=== 198getName: string(3) "ref" 199isPassedByReference: bool(true) 200 201Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 202getClass: NULL 203getDeclaringClass: test 204isArray: 205Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 206bool(false) 207allowsNull: bool(true) 208isOptional: bool(false) 209isDefaultValueAvailable: bool(false) 210===3=== 211getName: string(3) "std" 212isPassedByReference: bool(false) 213 214Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 215getClass: stdClass 216getDeclaringClass: test 217isArray: 218Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 219bool(false) 220allowsNull: bool(false) 221isOptional: bool(false) 222isDefaultValueAvailable: bool(false) 223===4=== 224getName: string(2) "na" 225isPassedByReference: bool(false) 226 227Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 228Class "NonExistingClass" does not exist 229getDeclaringClass: test 230isArray: 231Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 232bool(false) 233allowsNull: bool(false) 234isOptional: bool(false) 235isDefaultValueAvailable: bool(false) 236===5=== 237getName: string(3) "opt" 238isPassedByReference: bool(false) 239 240Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 241getClass: stdClass 242getDeclaringClass: test 243isArray: 244Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 245bool(false) 246allowsNull: bool(true) 247isOptional: bool(true) 248isDefaultValueAvailable: bool(true) 249getDefaultValue: NULL 250===6=== 251getName: string(3) "def" 252isPassedByReference: bool(false) 253 254Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d 255getClass: NULL 256getDeclaringClass: test 257isArray: 258Deprecated: Method ReflectionParameter::isArray() is deprecated in %s on line %d 259bool(false) 260allowsNull: bool(true) 261isOptional: bool(true) 262isDefaultValueAvailable: bool(true) 263getDefaultValue: string(6) "FooBar" 264