parameters_002.phpt 7.1 KB

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