1--TEST-- 2ReflectionParameter class - getNames() method. 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8class ReflectTestClass { 9 public static function twoArgFunction($theIncrement, $anotherParam) { 10 return ++$theIncrement; 11 } 12 13 public function oneArgNonStatic($theParam) { 14 $theParam--; 15 } 16 17 public function noArgs() { 18 echo "No arg function\n"; 19 } 20} 21 22// Create an instance of the Reflection_Method class 23$method = new ReflectionMethod('ReflectTestClass', 'twoArgFunction'); 24// Get the parameters 25$parameters = $method->getParameters(); 26echo "Parameters from twoArgMethod:\n\n"; 27foreach($parameters as $parameter) { 28 var_dump($parameter); 29 $name = $parameter->getName(); 30 echo "\n"; 31} 32 33$method = new ReflectionMethod('ReflectTestClass', 'oneArgNonStatic'); 34$parameters = $method->getParameters(); 35echo "Parameters from oneArgNonStatic:\n\n"; 36foreach($parameters as $parameter) { 37 var_dump($parameter); 38 $name = $parameter->getName(); 39 echo "\n"; 40} 41 42 43$method = new ReflectionMethod('ReflectTestClass', 'noArgs'); 44$parameters = $method->getParameters(); 45echo "Parameters from noArgs:\n\n"; 46var_dump($parameters); 47foreach($parameters as $parameter) { 48 var_dump($parameter); 49 $name = $parameter->getName(); 50 echo "\n"; 51} 52 53echo "done\n"; 54 55?> 56--EXPECTF-- 57Parameters from twoArgMethod: 58 59object(ReflectionParameter)#%i (1) { 60 ["name"]=> 61 string(12) "theIncrement" 62} 63 64object(ReflectionParameter)#%i (1) { 65 ["name"]=> 66 string(12) "anotherParam" 67} 68 69Parameters from oneArgNonStatic: 70 71object(ReflectionParameter)#%i (1) { 72 ["name"]=> 73 string(8) "theParam" 74} 75 76Parameters from noArgs: 77 78array(0) { 79} 80done 81