Call me loony but I see nothing surprising here. It's just indirection... I guess I've probably got some Elder Thing blood in me.
It isn't something you can easily debug and it is complicated. That said, it isn't the gates to hell that it is represented as. It's a tool, and it can make code cleaner if you want it to.
function __tostring(){ $items = ['title','header','comment'] foreach($items as $item){ echo $this->$item; } }
Make that list of class variables much longer and you start to see the benefits in certain cases.
There are times when I do miss variable variables.
def print_string(self):
items = ['title', 'header', 'comment']
for item in items:
print getattr(self, item)
Where "getattr" is just a pretty protocol for calling ... self.__dict__[item]
This extends to whatever you want, including members of namespaces (like declared classes, functions, other namespaces, etc...)Edited for clarity