大网数据广告活动
PHP 语言与运行手册

ReflectionParameter 类

· 52CE 我爱测

要自行检查函数的参数,首先创建 ReflectionFunction 或 ReflectionMethod 的实例,然后使用它们的 ReflectionFunctionAbstract::getParameters() 方法来检索参数的数组。

ReflectionParameter 类

(PHP 5, PHP 7, PHP 8)

简介

ReflectionParameter 检索函数或方法参数的相关信息。

要自行检查函数的参数,首先创建 ReflectionFunction 或 ReflectionMethod 的实例,然后使用它们的 ReflectionFunctionAbstract::getParameters() 方法来检索参数的数组。

类摘要

class ReflectionParameter implements Reflector {
/* 属性 */
public string $name;
/* 方法 */
public function __construct(string|array|object $function, int|string $param)
public function allowsNull(): bool
public function canBePassedByValue(): bool
private function __clone(): void
public static function export(string $function, string $parameter, bool $return = ?): string
public function getAttributes(?string $name = null, int $flags = 0): array
#[\Deprecated(
    since: '8.0',
    message: "use ReflectionParameter::getType() instead",
)]

public function getClass(): ?ReflectionClass
public function getDefaultValue(): mixed
public function getName(): string
public function getPosition(): int
public function getType(): ?ReflectionType
public function hasType(): bool
#[\Deprecated(
    since: '8.0',
    message: "use ReflectionParameter::getType() instead",
)]

public function isArray(): bool
#[\Deprecated(
    since: '8.0',
    message: "use ReflectionParameter::getType() instead",
)]

public function isCallable(): bool
public function isDefaultValueAvailable(): bool
public function isDefaultValueConstant(): bool
public function isOptional(): bool
public function isPassedByReference(): bool
public function isPromoted(): bool
public function isVariadic(): bool
public function __toString(): string
}

属性

name

参数名。只读,在尝试赋值的时候会抛出 ReflectionException。

更新日志

版本 说明
8.0.0 已移除 ReflectionParameter::export()。

目录

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。