ReflectionParameter

The ReflectionParameter class retrieves information about a function's or method's parameters.

<?php
  class ReflectionParameter implements Reflector {
      public string getName()
      public ReflectionClass getClass()
      public bool allowsNull()
      public bool isPassedByReference()
      public string toString()
  }
?>

To introspect function parameters, you will first have to create an instance of the ReflectionFunction or ReflectionMethod classes and then use their getParameters method to retrieve an array of parameters.

Example 14-3. Using the ReflectionParameter class

<?php
    function foo($a, $b, $c) { }
    function bar(Exception $a, &$b, $c) { }
    function baz($a= 1, $b= NULL, ReflectionFunction $c) { }
    function abc() { }

    // Create an instance of ReflectionFunction with the
    // parameter given from the command line.    
    $reflect= new ReflectionFunction($argv[1]);

    echo $reflect->toString();
    foreach ($reflect->getParameters() as $i => $param) 
    {
        printf(
            "-- Parameter #%d: %s {\n".
            "   Class: %s\n".
            "   Allows NULL: %s\n".
            "   Passed to by reference: %s\n".
            "}\n",
            $i, 
            $param->getName(),
            var_export($param->getClass(), 1),
            var_export($param->allowsNull(), 1),
            var_export($param->isPassedByReference(), 1)
        );
    }
?>