sajadsdi/php-reflection

用于获取类反射的工具

1.0.0 2023-12-07 01:26 UTC

This package is auto-updated.

Last update: 2024-09-21 04:05:52 UTC


README

PHP Reflection库提供了一套在PHP中执行类反射的工具。它允许您使用PHP内置的反射功能检索有关类、属性、方法和常量的信息。

安装

您可以通过Composer安装PHP Reflection库。在项目目录中运行以下命令

composer require sajadsdi/php-reflection

使用方法

要使用Reflections库,请按照以下步骤操作

  1. Reflections类导入到您的PHP文件中
use Sajadsdi\PhpReflection\Reflections;
  1. 创建一个Reflections类的实例(使用单例以获得更好的性能)
$reflections = new Reflections();

3.0.执行类反射

$class = new MyClass();
$reflectionClass = $reflections->reflection($class);

//or
$reflectionClass = $reflections->reflection(MyClass::class);

3.1.检索属性、方法或常量

$properties = $reflections->properties(MyClass::class);
$methods = $reflections->methods(MyClass::class);
$constants = $reflections->constants(MyClass::class);

贡献

欢迎贡献!如果您发现任何问题或对改进有建议,请打开问题或在GitHub仓库提交拉取请求。

许可证

此库是开源的,并按照MIT许可证发布。有关更多信息,请参阅LICENSE文件。

致谢

PHP Reflection库由SajaD SaeeDi开发和维护。

请随意在您的项目中使用此库,并享受PHP中类反射的力量!