I'm a PHP developer coding in the Yii 1.x framework. I was looking for a way to encode unescaped JSON in Yii 1.x, and found the CJSON
framework class for this purpose (so OOP).
Since it does not support unescaped JSON though, I had to revert back to the pure PHP, procedural, non-OOP approach of using json_encode($results, JSON_UNESCAPED_SLASHES);
. However, I asked how to achieve the same with the Yii framework.
As an answer I received information that, while it does what I want, is not possible with the base framework and requires that I extend a base class. This proposed solution requires 12 lines of code and involves creation of a separate file, while my solution requires just 1 new line of code.
Just to feed my curiosity - what is more important in situations like this? Should I follow KISS and make my code as simple as possible, even reverting to procedural code, or should I stick to OOP solutions and always extend classes if I can't do what I need with existing framework code?
CJSON::encode()
is a static method, so the class is little more than a namespace. Being attached to a class doesn't somehow make it better than using a free function.