tags:

views:

194

answers:

3

I have returned to php development from Moose and I really miss CLOS like object model for php. Is there some kind of syntaxtic sugar which would allow me to write less code in php when dealing with objects?

Just to stress this requirement a bit more. I don't want to write one thing in several places. I can live with part of code being generated automatically, but in the code that I have to see to develop I don't want to see redundant information which is just clutter (think: LISP macro if you really need more analogy). So this part can be also called DSL if that makes more sense.

I would love to have at least roles (mixins), and some kind of introspection without re-inventing the weel. Code generators and auto-loaders might be one way to solve at least part of this problem.

p.s. For JavaScript there is Joose, so similar API would be very useful.

+2  A: 

There are no mixins in php yet but there is an RFC for traits which will work roughly the same. http://wiki.php.net/rfc/traits

Using overloading for __call can allow you to dispatch methods to other classes and have it look like a mixin.

MOdMac
Is there any hope to have it in official php any time soon?
dpavlin
+1  A: 

The Symfony project has a mechanism for mixins, allowing aspect oriented programming like in CLOS. Personally, I don't like this kind of hacking in userland spacee (At least not with PHP). I think you would be better off using the features that the language provides, and perhaps wait for something like traits to (maybe) make its way into the language.

troelskn
While it does seem like a nice framework, it fails initial requirement of less code, especially __construct in example that you linked. After few readings it still seems completely redundant to me.
dpavlin
I don't particularly like it either, but it's there, if you want it.
troelskn
A: 

There is also new project http://github.com/huberry/phuby which implements roles in php!

dpavlin