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-crowbarAssume 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; // ApplesYou can set the property:
Crowbar::pry($crate)->content; // Original: Apples
Crowbar::pry($crate)->content = 'Strawberries';
Crowbar::pry($crate)->content; // Altered: StrawberriesYou can also invoke private methods:
Crowbar::pry($crate)->peek(); // Strawberriescomposer testPlease 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.
