dkx / private-properties-accessor
此包已被废弃,不再维护。未建议替代包。
无需反射即可访问私有属性的访问器
0.1.0
2019-08-23 06:42 UTC
Requires
- php: ^7.3
Requires (Dev)
- phpstan/extension-installer: >=1.0
- phpstan/phpstan: >=0.11
- phpstan/phpstan-phpunit: >=0.11
- phpstan/phpstan-strict-rules: >=0.11
- phpunit/phpunit: >=8.0
This package is auto-updated.
Last update: 2024-01-23 16:47:15 UTC
README
无需反射即可访问私有属性的访问器
基于 https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/
安装
$ composer require dkx/private-properties-accessor
使用方法
<?php
declare(strict_types=1);
use DKX\PrivatePropertiesAccessor\PrivatePropertiesAccessor;
$accessor = new PrivatePropertiesAccessor($class);
$prop = & $accessor->getProperty('propFromClass');
$prop = 'hello world';
var_dump($class->propFromClass); // output: hello world
获取所有属性
<?php
$props = $accessor->getProperties();
此方法使用 get_object_vars
函数,这意味着它将不会返回父类的私有属性。