I am trying to decide on what should be the/my Best Practice when it comes to class properties in PHP.
Should I use public properties which means a lot less code, especially when it comes to serializing an object, or iterating over its properties?
The problem is compounded by the ability to assign arbitrarily named values to an object at runtime which I see as leading inevitably to hidden and emergent bugs: it is not in the class definition so I assign an arbitrary property name that someone else chooses and uses elsewhere. Not to mention simple typos of course ;-)
Should I just use the magic methods get and set and store all object data in an array whose scope is private or protected?
Or should I do the classic OOP thing and encapsulate object data and use explicit getters and setters?
I would love some solid advice from the gurus here, from those who have been involved in large projects where the pitfalls of each option are exposed.