dkx/private-properties-accessor

This package is abandoned and no longer maintained. No replacement package was suggested.

Accessor for private properties without reflection

0.1.0 2019-08-23 06:42 UTC

This package is auto-updated.

Last update: 2024-01-23 16:47:15 UTC


README

Accessor for private properties without reflection

Based on https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/

Installation

$ composer require dkx/private-properties-accessor

Usage

<?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

Get all properties

<?php

$props = $accessor->getProperties();

This method uses get_object_vars function which means that it will not return parent private properties.