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.
In questa pagina del sito puoi guardare il video online PHP Reflection and Attributes for Feed Example della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Chris Ridings 24 ottobre 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 82 volte e gli è piaciuto 3 spettatori. Buona visione!