Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: ReflectionParameter::__construct - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionParameter::__construct

2025-04-28

ReflectionParameter::__construct

(PHP 5, PHP 7, PHP 8)

ReflectionParameter::__constructConstruct

说明

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

Constructs a ReflectionParameter instance.

参数

function

The function to reflect parameters from.

param

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

示例

示例 #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->getParameters() 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->getPosition() can be used
$param->getName(),
var_export($param->getClass(), 1),
var_export($param->allowsNull(), 1),
var_export($param->isPassedByReference(), 1),
$param->isOptional() ? 'yes' : 'no'
);
}
?>

以上示例的输出类似于:

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
}

参见

添加备注

用户贡献的备注 1 note

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

官方地址:https://www.php.net/manual/en/reflectionparameter.construct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3