定制 christopheraseidl/reflect 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

christopheraseidl/reflect

Composer 安装命令:

composer require christopheraseidl/reflect

包简介

A simple class for facilitating quicker use of PHP's ReflectionClass.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Reflect is a simple wrapper around PHP's ReflectionClass that provides easy access to private properties and methods, supporting both instanced and static members with inheritance.

PHP Versions

  • PHP 8.0+

Installation

You can install Reflect via composer:

composer require christopheraseidl/reflect

Usage

Accessing instance members

class MyClass {
    private string $private = 'private property';
    private function method(): string 
    {
        return 'private method';
    }
}

$reflect = Reflect::on(new MyClass());
echo $reflect->private; // 'private property'
echo $reflect->method(); // 'private method'

Accessing static members

class MyStaticClass {
    private static string $static = 'static property';
    private static function staticMethod(): string 
    {
        return 'static method';
    }
}

$reflect = Reflect::on(MyStaticClass::class);
echo $reflect->static; // 'static property'
echo $reflect->staticMethod(); // 'static method'

Inheritance support

class ParentClass {
    private string $parentProp = 'parent property';
}

class Child extends ParentClass {
    private string $childProp = 'child property';
}

$reflect = Reflect::on(new Child());
echo $reflect->parentProp; // 'parent property'
echo $reflect->childProp; // 'child property'

Non-instantiable classes

abstract class AbstractClass {
    private static string $env = 'development';
}

$reflect = Reflect::on(AbstractClass::class);
echo $reflect->env; // 'development'

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-25