• Tag Archives
  • PHP
  • 2 Posts

Stop abusing arrays in PHP

This is an issue i’ve wanted to get of my chest for a long time. It’s been latently brewing inside me for a considerable amount of time and it’s starting to come to a head. The issue is with PHP and the total abuse of arrays. Whether this issue is an artifact of the language’s historical baggage or because PHP just attracts a lot of inexperienced developers is up for debate. My problem here is that arrays are nearly always used where objects should be!

Implementing dynamic, read-only object properties in PHP

I was recently working on a PHP project where i needed (or would of liked) an object to have publicly available properties which were read-only. Unfortunately PHP doesn’t support this and the usual way of implementing something similar was to have private properties and standard getter methods. The trouble with getter methods is that sometimes they seem a little like overkill, especially if you’re only accessing a name or an age, etc. Do you really need a method call to return a simple string or number that is always the same? Plus, in my opinion, they are harder to read than properties, although it could be argued only slightly.