ReflectionParameter_002.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. ReflectionParameter class - isPassedByReferenceMethod()
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --FILE--
  7. <?php
  8. class ReflectTestClass {
  9. public static function staticMethod(&$paramOne, $anotherParam) {
  10. return ++$theIncrement;
  11. }
  12. public function instanceMethod($firstParam, &$secondParam) {
  13. $firstParam = "Hello\n";
  14. }
  15. }
  16. // Create an instance of the Reflection_Method class
  17. $method = new ReflectionMethod('ReflectTestClass', 'staticMethod');
  18. // Get the parameters
  19. $parameters = $method->getParameters();
  20. echo "Parameters from staticMethod:\n\n";
  21. foreach($parameters as $parameter) {
  22. var_dump($parameter);
  23. if($parameter->isPassedByReference()) {
  24. echo "This param is passed by reference\n";
  25. } else {
  26. echo "This param is not passed by reference\n";
  27. }
  28. echo "\n";
  29. }
  30. // Create an instance of the Reflection_Method class
  31. $method = new ReflectionMethod('ReflectTestClass', 'instanceMethod');
  32. // Get the parameters
  33. $parameters = $method->getParameters();
  34. echo "Parameters from instanceMethod:\n\n";
  35. foreach($parameters as $parameter) {
  36. var_dump($parameter);
  37. if($parameter->isPassedByReference()) {
  38. echo "This param is passed by reference\n";
  39. } else {
  40. echo "This param is not passed by reference\n";
  41. }
  42. echo "\n";
  43. }
  44. echo "done\n";
  45. ?>
  46. --EXPECTF--
  47. Parameters from staticMethod:
  48. object(ReflectionParameter)#%i (1) {
  49. ["name"]=>
  50. string(8) "paramOne"
  51. }
  52. This param is passed by reference
  53. object(ReflectionParameter)#%i (1) {
  54. ["name"]=>
  55. string(12) "anotherParam"
  56. }
  57. This param is not passed by reference
  58. Parameters from instanceMethod:
  59. object(ReflectionParameter)#%i (1) {
  60. ["name"]=>
  61. string(10) "firstParam"
  62. }
  63. This param is not passed by reference
  64. object(ReflectionParameter)#%i (1) {
  65. ["name"]=>
  66. string(11) "secondParam"
  67. }
  68. This param is passed by reference
  69. done