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(ReflectionMethod::createFromMethodName('test::method')); 73 74?> 75--EXPECTF-- 76Deprecated: test(): Implicitly marking parameter $opt as nullable is deprecated, the explicit nullable type must be used instead in %s on line %d 77#####test()##### 78===0=== 79getName: string(3) "nix" 80isPassedByReference: bool(false) 81 82Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 83getClass: NULL 84getDeclaringClass: NULL 85isArray: 86Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 87bool(false) 88allowsNull: bool(true) 89isOptional: bool(false) 90isDefaultValueAvailable: bool(false) 91===1=== 92getName: string(2) "ar" 93isPassedByReference: bool(false) 94 95Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 96getClass: NULL 97getDeclaringClass: NULL 98isArray: 99Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 100bool(true) 101allowsNull: bool(false) 102isOptional: bool(false) 103isDefaultValueAvailable: bool(false) 104===2=== 105getName: string(3) "ref" 106isPassedByReference: bool(true) 107 108Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 109getClass: NULL 110getDeclaringClass: NULL 111isArray: 112Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 113bool(false) 114allowsNull: bool(true) 115isOptional: bool(false) 116isDefaultValueAvailable: bool(false) 117===3=== 118getName: string(3) "std" 119isPassedByReference: bool(false) 120 121Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 122getClass: stdClass 123getDeclaringClass: NULL 124isArray: 125Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 126bool(false) 127allowsNull: bool(false) 128isOptional: bool(false) 129isDefaultValueAvailable: bool(false) 130===4=== 131getName: string(2) "na" 132isPassedByReference: bool(false) 133 134Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 135Class "NonExistingClass" does not exist 136getDeclaringClass: NULL 137isArray: 138Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 139bool(false) 140allowsNull: bool(false) 141isOptional: bool(false) 142isDefaultValueAvailable: bool(false) 143===5=== 144getName: string(3) "opt" 145isPassedByReference: bool(true) 146 147Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 148getClass: stdClass 149getDeclaringClass: NULL 150isArray: 151Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 152bool(false) 153allowsNull: bool(true) 154isOptional: bool(true) 155isDefaultValueAvailable: bool(true) 156getDefaultValue: NULL 157===6=== 158getName: string(3) "def" 159isPassedByReference: bool(false) 160 161Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 162getClass: NULL 163getDeclaringClass: NULL 164isArray: 165Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 166bool(false) 167allowsNull: bool(true) 168isOptional: bool(true) 169isDefaultValueAvailable: bool(true) 170getDefaultValue: string(6) "FooBar" 171#####test::method()##### 172===0=== 173getName: string(3) "nix" 174isPassedByReference: bool(false) 175 176Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 177getClass: NULL 178getDeclaringClass: test 179isArray: 180Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 181bool(false) 182allowsNull: bool(true) 183isOptional: bool(false) 184isDefaultValueAvailable: bool(false) 185===1=== 186getName: string(2) "ar" 187isPassedByReference: bool(false) 188 189Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 190getClass: NULL 191getDeclaringClass: test 192isArray: 193Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 194bool(true) 195allowsNull: bool(false) 196isOptional: bool(false) 197isDefaultValueAvailable: bool(false) 198===2=== 199getName: string(3) "ref" 200isPassedByReference: bool(true) 201 202Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 203getClass: NULL 204getDeclaringClass: test 205isArray: 206Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 207bool(false) 208allowsNull: bool(true) 209isOptional: bool(false) 210isDefaultValueAvailable: bool(false) 211===3=== 212getName: string(3) "std" 213isPassedByReference: bool(false) 214 215Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 216getClass: stdClass 217getDeclaringClass: test 218isArray: 219Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 220bool(false) 221allowsNull: bool(false) 222isOptional: bool(false) 223isDefaultValueAvailable: bool(false) 224===4=== 225getName: string(2) "na" 226isPassedByReference: bool(false) 227 228Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 229Class "NonExistingClass" does not exist 230getDeclaringClass: test 231isArray: 232Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 233bool(false) 234allowsNull: bool(false) 235isOptional: bool(false) 236isDefaultValueAvailable: bool(false) 237===5=== 238getName: string(3) "opt" 239isPassedByReference: bool(false) 240 241Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 242getClass: stdClass 243getDeclaringClass: test 244isArray: 245Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 246bool(false) 247allowsNull: bool(true) 248isOptional: bool(true) 249isDefaultValueAvailable: bool(true) 250getDefaultValue: NULL 251===6=== 252getName: string(3) "def" 253isPassedByReference: bool(false) 254 255Deprecated: Method ReflectionParameter::getClass() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 256getClass: NULL 257getDeclaringClass: test 258isArray: 259Deprecated: Method ReflectionParameter::isArray() is deprecated since 8.0, use ReflectionParameter::getType() instead in %s on line %d 260bool(false) 261allowsNull: bool(true) 262isOptional: bool(true) 263isDefaultValueAvailable: bool(true) 264getDefaultValue: string(6) "FooBar" 265