arokettu/private-access

读取私有属性和调用私有方法简单快捷的方法

3.0.0 2023-01-14 12:47 UTC

This package is auto-updated.

Last update: 2024-09-20 04:34:00 UTC


README

Packagist License Gitlab pipeline status

一个小巧的库,用于访问对象的私有属性。实际上它更像是一个炫技的例子,而不是一个有用的工具。不调用反射API!

安装

使用composer

composer require arokettu/private-access --dev

用法

这四个简单的函数可以作为像PsySH这样的辅助工具

  • get_private_field()
  • set_private_field()
  • call_private_method()
  • get_private_const()

示例

<?php

class X {
    private $field = 123;
}

$x = new X();

var_dump(\Arokettu\Debug\get_private_field($x, 'field')); // 123
\Arokettu\Debug\set_private_field($x, 'field', 321); // $x->field = 321;

文档

在这里阅读完整文档: https://sandfox.dev/php/private-access.html

也在Read the Docs上: https://php-private-access.readthedocs.io/

支持

请在GitLab的我们主要仓库中提交问题: https://gitlab.com/sandfox/php-private-access/-/issues

许可证

该库在MIT许可证下以开源形式提供。