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