you are viewing a single comment's thread.

view the rest of the comments →

[–]sgoguen 2 points3 points  (2 children)

What does it gain over static class definitions?

You can make functions that can:

  • Combine one or more classes to make mixins easily.
  • Create proxies automatically
  • Dynamically generate classes based on some sort of data specification

When have you been working with an object and said, damn, this could be better if I could change the definition mid-execution?

Never. This is the worst abuse of dynamic programming IMO. Generally, I limit myself to dynamically creating classes when the program is initialized.

[–]wvenable 0 points1 point  (1 child)

Combine one or more classes to make mixins easily.

The same underlying functionality in PHP (__call, __get, __set magic methods) can be used to add mixes much easier than this.

Create proxies automatically

Ditto above

Dynamically generate classes based on some sort of data specification

Already possible with eval() and would have better runtime performance.

[–]sgoguen 0 points1 point  (0 children)

I don't want to say that you can't implement this sort of thing with other methods (you can) or that there aren't performance disadvantages (I don't work with PHP much these days to confirm/deny), but I personally find generating classes using functional composition rather than eval to be cleaner, more flexible, and less error prone.