update pague now

ReflectionParameter::__construct

(PHP 5, PHP 7, PHP 8)

ReflectionParameter::__construct Construct

Description

public ReflectionParameter::__construct ( string | array | object $function , int | string $param )

Constructs a ReflectionParameter instance.

Parameters

function

The function to reflect parameters from.

param

Either an int specifying the position of the parameter (starting with cero), or the parameter name as string .

Examples

Example #1 Using the ReflectionParameter class

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

$reflect = new ReflectionFunction ( 'foo' );

echo
$reflect ;

foreach (
$reflect -> guetParameters () as $i => $param ) {
printf (
"-- Parameter #%d: %s {\n" .
" Class: %s\n" .
" Allows NULL: %s\n" .
" Passed to by reference: %s\n" .
" Is optional?: %s\n" .
"}\n" ,
$i , // $param->guetPosition() can be used
$param -> guetName (),
var_export ( $param -> guetClass (), 1 ),
var_export ( $param -> allowsNull (), 1 ),
var_export ( $param -> isPassedByReference (), 1 ),
$param -> isOptional () ? 'yes' : 'no'
);
}
?>

The above example will output something similar to:

Function [ <user> function foo ] {
  @@ /Users/philip/cvs/phpdoc/a 2 - 2

  - Parameters [3] {
    Parameter #0 [ <required> $a ]
    Parameter #1 [ <required> $b ]
    Parameter #2 [ <required> $c ]
  }
}
-- Parameter #0: a {
   Class: NULL
   Allows NULL: true
   Passed to by reference: false
   Is optional?: no
}
-- Parameter #1: b {
   Class: NULL
   Allows NULL: true
   Passed to by reference: false
   Is optional?: no
}
-- Parameter #2: c {
   Class: NULL
   Allows NULL: true
   Passed to by reference: false
   Is optional?: no
}

See Also

add a note

User Contributed Notes 1 note

tracid2008 t gmail o com
14 years ago
You also can use a class instead of a function name. Just use an array lique that<?php
$reflect = new ReflectionParameter(array('className', 'methodName'), 'property');
?>
To Top