CLOS 类似 PHP 的对象模型

发布于 2024-07-06 10:15:47 字数 561 浏览 11 评论 0原文

我已经从 Moose 返回到 php 开发,我真的很怀念 CLOS 之类的 php 对象模型。 是否有某种语法糖可以让我在处理对象时在 php 中编写更少的代码

只是为了再强调一下这个要求。 我不想把一件事写在几个地方。 我可以接受自动生成的部分代码,但在我必须看到的开发代码中,我不想看到混乱的冗余信息(想想:LISP 宏,如果你真的需要更多类比)。 因此,如果更有意义的话,这部分也可以称为 DSL。

我希望至少拥有角色(mixins),以及某种内省,而无需重新发明 Weel。 代码生成器和自动加载器可能是解决至少部分问题的一种方法。

ps 对于 JavaScript,有 Joose,因此类似的 API 会非常有用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

触ぅ动初心 2024-07-13 10:15:47

php 中还没有 mixins,但是有一个关于 Trait 的 RFC,其工作原理大致相同。 http://wiki.php.net/rfc/traits

使用 __call 重载可以让您将方法分派给其他类并使其看起来像一个 mixin。

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.

瞄了个咪的 2024-07-13 10:15:47

Symfony 项目有一个 mixin 机制,允许面向方面像在 CLOS 中一样编程。 就我个人而言,我不喜欢用户空间中的这种黑客行为(至少不喜欢 PHP)。 我认为您最好使用该语言提供的功能,并且也许等待诸如特征之类的东西(也许)进入该语言。

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.

攀登最高峰 2024-07-13 10:15:47

还有一个新项目 http://github.com/huberry/phuby 在 php 中实现角色!

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文