Metaprogramming: Metaprogramming treats code as data that can be examined and manipulated programmatically — generating boilerplate, adding behaviour, or building DSLs without hand-writing every line. Metaprogramming is writing code that reads, generates or changes other code. Instead of writing every repetitive piece by hand, a program creates it, or adapts behaviour at runtime based on structure.
You use it more often than you might think. PHP attributes read by a framework, Laravel's magic methods that turn whereEmail() into a query, reflection that builds forms from a class definition, and code generators for API clients are all metaprogramming.
What should you keep in mind with Metaprogramming?
It removes boilerplate and enables elegant APIs. The cost is that behaviour becomes less visible. Magic methods do not show up in a plain text search, and editors may not understand them without help files or PHPDoc annotations. Use it where it clearly saves effort, and document the magic for the next developer.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.