Meta-programming with reflection and attributes
The phrase "meta-programming" describes a technique where your code and runtime become data that you can work with. It can be a bit mind-bending, but also awesomely powerful.
Reflection
PHP comes with something called reflection, which allows you to examine your code and objects at runtime.
PHP: Reflection - Manual
https://www.php.net/manual/en/book.reflection.php
I think the name "reflection" is really apt. It brings to mind a monk, meditating on their own nature and searching for a path to enlightenment.
Reflection is most useful in library code and is used extensively in projects such as Doctrine ORM (which you really should have a look at if you want to work with databases).
GitHub - doctrine/orm: Doctrine Object Relational Mapper (ORM)
https://github.com/doctrine/orm
Let's have a look at some simple code using reflection to meddle with a simple PHP class.
First, we have our simple...