This package allows you to access methods / properties in a class with a restricted access modifier i.e. private
/ protected
.
You can install the package via composer:
composer require dive-be/php-crowbar
Assume the following class with a private
property.
It offers no way to read / write its $content
property.
class SealedCrate
{
public function __construct(
private string $content,
) {}
private function peek(): string
{
return $this->content;
}
}
$crate = new SealedCrate('Apples');
You can get the property using the Crowbar
:
Crowbar::pry($crate)->content; // Apples
You can set the property:
Crowbar::pry($crate)->content; // Original: Apples
Crowbar::pry($crate)->content = 'Strawberries';
Crowbar::pry($crate)->content; // Altered: Strawberries
You can also invoke private methods:
Crowbar::pry($crate)->peek(); // Strawberries
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email oss@dive.be instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.