Skip to main content

Posts

Showing posts from September, 2014

PHP Savers - PropertyBag !!!

The ubiquitous and the universal data structure in PHP is the array. It is an amalgamation of commonly used data structures - list, map etc. In the recent times, PHP has also adopted object orientation and introduced classes. The syntactic difference in the way a property of an array and object poses an inconvenience in the user code1 specifically when there is a need to interact with code that is not open for change; legacy or not.
JavaScript would allow you to access an object property either obj.propName or obj["propName"]. That does come in handy for sure. Besides, accessing the property by [] tags is the only way if the property name contains characters like hyphen: obj["prop-Name"]. At the user code level, it is fair to see an object as a bag of key-value pairs.
Along the same lines, it is not wrong to expect the same in PHP between an object and an array; although there is a fundamental difference2. The expectation arises when there is a lot of code that ge…