CLOS as an object model for PHP

I returned to php development from Moose , and I really miss the CLOS object model for php. Is there some kind of synthetic sugar that would allow me to write less code in php when working with objects?

Just emphasize this requirement a little more. I do not want to write one thing in several places. I can live with part of the generated code automatically, but in the code that I need to see in order to develop, I don’t want to see redundant information that is just messy (think: LISP macro if you really need an additional analogy). Therefore, this part can also be called DSL, if that makes sense.

I would like to have at least roles (mixins) as well as introspection without reinvention. Code generators and autoloaders can be one way to solve at least part of this problem.

ps There is Joose for JavaScript, so a similar API would be very useful.

+4
source share
3 answers

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

0
source

There are no mixins in php yet, but there are RFCs for traits that will work roughly the same. http://wiki.php.net/rfc/traits

Using overloading for __call may allow you to send methods to other classes and look like mixin.

+2
source

The Symfony project has a mechanism for mixins that allows aspect-oriented programming, as in CLOS. Personally, I do not like such a hack in user space (at least not with PHP). I think it would be better for you to use the functions that the language provides, and perhaps wait for something like hell (possibly) to break into the language.

+1
source

Source: https://habr.com/ru/post/1277420/


All Articles