I want to start making short videos about PHP from time to time. The idea is that they are quick to produce - so this is more me explaining my thought process as I program something how it is done in the real world and with any silly mistakes left in. Here we want to have a class representing a news item and some sort of feed system (JSON/XML). In the future there may be more classes - like a blog class.
Normally we should always program the simplest method possible. The obvious simplest method would be to have a feed class for each type (possibly inherited) and hard code in the fields. This is what AI coding would probably give you. However, it's unsatisfactory because the Feed class is not generic and more importantly because any future programmer changing classes like the news item class would need to know that they also need to edit the hard coded fields in the relevant code.
So here my argument is that you should make the trade off. Using attributes and reflection we can make a generic feed class and simultaneously make it obvious to somebody editing the news item (or future blog class) that they need to add an attribute to enable the field and they only need to work on the one file (without needing to know the other one exists). Because future work is more likely to be on the other classes, this trade off in the feed class is well worth it.
On this page of the site you can watch the video online PHP Reflection and Attributes for Feed Example with a duration of hours minute second in good quality, which was uploaded by the user Chris Ridings 24 October 2025, share the link with friends and acquaintances, this video has already been watched 82 times on youtube and it was liked by 3 viewers. Enjoy your viewing!