dhenfie/accessible

1.2.0 2023-10-04 15:00 UTC

This package is auto-updated.

Last update: 2024-12-23 18:42:23 UTC


README

About

A simple utility that allows accessing private methods and private properties outside of the class.

Install

Install via composer.

composer require dhenfie/accessible

Usage

Use the accessible($targetObject) function to introspect the target object, and after that, you can access private methods as if they were public methods.

Example:

<?php

use function Dhenfie\Accessible\accessible;

require 'vendor/autoload.php';

$person = new Person(name: 'Fajar Susilo');

// call private method 'getFilterName()'
echo accessible($person)->getFilterName('uppercase');

The accessible() function can also be used for object properties.

Example:

<?php

use function Dhenfie\Accessible\accessible;

require 'vendor/autoload.php';

$person = new Person(name: 'Fajar Susilo');

// accessing private property '$name'
echo accessible($person)->name;

// set value private property '$name'
accessible($person)->name = 'Taylor Otwell';