Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active February 4, 2026 12:48
Show Gist options
  • Select an option

  • Save mcsee/a6a0b099c28a609c2e48df811dc5294d to your computer and use it in GitHub Desktop.

Select an option

Save mcsee/a6a0b099c28a609c2e48df811dc5294d to your computer and use it in GitHub Desktop.
This gist belongs to the Clean Code Cookbook https://cleancodecookbook.com by Maximiliano Contieri https://maximilianocontieri.com
<?
/** @var User[] $users */
// this is a static declaration used by many IDEs but not the compiler
// Like many comments it is useless, and possible outdated
function notifyUsers(array $users) {
foreach ($users as $user) {
// You have no guarantee $user is actually a User object
// The comment above is
// just a hint for the IDE/Static Analysis
$user->sendNotification();
}
}
$users = [new User('Anatoli Bugorski'), new Product('Laser')];
// This array is anemic and lacks runtime type enforcement
// There's a Product in the collection and will show a fatal error
// unless it can understand #sendNotification() method
notifyUsers($users);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment