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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners