PHP

★ How to easily access private properties and methods in PHP

[AdSense-A]

Sometimes you need to access a private property or method on an object that isn't yours. Maybe you're writing a test and need to assert some internal state. Maybe you're building a package that needs to reach into another object's internals. Whatever the reason, PHP's visibility rules are standing in your way.

Our spatie/invade package provides a tiny invade function that lets you read, write, and call private members on any object.

You probably shouldn't reach for this package often. It's most useful in tests or when you're building a package that needs to integrate deeply with objects you don't control.

Let me walk you through how it works.

(more…)

By hadi, ago
PHP

Selfish AI

Larry Garfield argues that the AI coding conversation focuses too much on individual productivity and ignores the broader societal costs. Read more

By hadi, ago