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.
Auf dieser Seite können Sie das Online-Video PHP Reflection and Attributes for Feed Example mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Chris Ridings 24 Oktober 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 82 Mal angesehen und es wurde von 3 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!