# RFC: Traits for PHP

- Thread: https://externals.io/message/35583
- Original archive: https://news-web.php.net/php.internals/35583
- Started by Mark van der Velden on 2008-02-19T10:42:45+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #35583 — Mark van der Velden — 2008-02-19T10:42:45+00:00

URL: https://externals.io/message/35583#35583

php@stefan-marr.de wrote:
> Hi,
> 
> [..]
> 
> Request for Comments: Traits for PHP
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> [..]

If it doesn't affect performance *MUCH* then I'm all for it ! It can
bring better structure for complex designs. Also by reusing, I'm
assuming less memory will be needed for the code base which is beneficial.


- Mark

---

## #35589 — Stefan Marr — 2008-02-19T12:09:24+00:00

URL: https://externals.io/message/35583#35589 · In reply to: #35583

Hi Mark,

> If it doesn't affect performance *MUCH* then I'm all for it ! It can
> bring better structure for complex designs. Also by reusing, I'm
> assuming less memory will be needed for the code base which is beneficial.
the current implementation does not save any memory compared to a
user-level copy'n'past solution. But there might be the opportunity to
optimize the op_array handling.

The performance impact is almost the same for a trait usage as for
inheritance or interface definitions. The only costly operation is
copying the method body from the trait to the class where it is used.
But this should be much cheaper than parsing the method for each
single class, what would be necessary if one would use a good old
copy'n'past approach.

Kind Regards
Stefan

---

## #35596 — Marcus Boerger — 2008-02-19T14:34:08+00:00

URL: https://externals.io/message/35583#35596 · In reply to: #35589

Hello Stefan,

  a userland copy'n'paste does not allow to reuse already compiled opcodes.
Traits do at least conceptionally.

marcus

Tuesday, February 19, 2008, 1:09:24 PM, you wrote:

> Hi Mark,

> > […]
> the current implementation does not save any memory compared to a
> user-level copy'n'past solution. But there might be the opportunity to
> optimize the op_array handling.

> The performance impact is almost the same for a trait usage as for
> inheritance or interface definitions. The only costly operation is
> copying the method body from the trait to the class where it is used.
> But this should be much cheaper than parsing the method for each
> single class, what would be necessary if one would use a good old
> copy'n'past approach.

> Kind Regards
> Stefan




Best regards,
 Marcus
