jclaveau/php-visibility-violator

Class providing simple helpers to violate the defined visibility of methods and properties

1.0.0 2019-03-20 01:37 UTC

This package is auto-updated.

Last update: 2024-12-20 14:01:06 UTC


README

This class provides simple helpers uppon basic features of the Reflection API to violate the visibility of properties and methods:

  • Modify or access privates properties of classes and instances
  • Call privates or protected methods

Quality

Build Status Scrutinizer Code Quality contributions welcome Viewed

Installation

The Visibility Violator is available via composer

composer require jclaveau/php-visibility-violator

Usage

use JClaveau\VisibilityViolator\VisibilityViolator;

$value = VisibilityViolator::getHiddenProperty($instance, 'property');
$value = VisibilityViolator::getHiddenProperty(MyClass::class, 'static_property');

VisibilityViolator::setHiddenProperty($instance, 'property', 'new value');
VisibilityViolator::setHiddenProperty(MyClass::class, 'static_property', 'new value');

$return = VisibilityViolator::callHiddenMethod($instance, 'method', $arguments);
$return = VisibilityViolator::callHiddenMethod(MyClass::class, 'staticMethod', ['argument 1', 'argument 2']);

Documentation