Last week, Caleb tweeted about a nifty function called invade - that he had made to easily work with private properties and methods. 😈 Whatcha think of my new favorite helper method?

Imagine you have this class defined which has a private property and method. class MyClass { private string $privateProperty = 'private value'; private function privateMethod(): string { return 'private return value'; }} $myClass = new Myclass(); This is how you can get the value of the private property using the invade function.

Accessing private properties and methods seems magical, but it's pretty easy to achieve using reflection.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners