johnpbloch/invade

A copy of the invade function from Livewire

v1.0.0 2022-02-11 16:53 UTC

This package is auto-updated.

Last update: 2024-11-11 23:41:56 UTC


README

Invade is a utility library shamelessly stolen from Livewire for Laravel. Using invade(), you can easily access all private and protected properties and methods of a class. This is nothing revolutionary or complicated, but it is terribly convenient. I created this as its own package for two reasons:

  1. I wanted to be able to require this function as a dev dependency, since I don't love the idea of this function being available in non-dev installations
  2. I wanted to use it in non-Laravel codebases

Installation

composer require --dev johnpbloch/invade

Usage

# supposing there is a class like this:
class StateManager {
    private $dataYouAreDebugging = [];
    /* ... */
}

# and supposing you have an instance of StateManager and you need to see that data:
/** @var StateManager $instance */
\var_dump(\invade($instance)->dataYouAreDebugging);

invade() will also give you the ability to set non-public properties and to call non-public methods.