Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7579741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:44:52+00:00 2026-05-30T17:44:52+00:00

I was reading an article about the new features in PHP 5.4.0. One of

  • 0

I was reading an article about the new features in PHP 5.4.0.
One of the most anticipated one being Traits.

Reading up on these Traits, to see what they’re all about, they simply look as compiler assisted copy-paste to me; and a language provided way to use composition, very much as used in the well-known Strategy Pattern which leverages the ‘favor composition over inheritance’ design principle.

Am I understanding this correctly?

What other advantages might these traits provide, that makes them worthwhile instead of just using the composition design principle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:44:54+00:00Added an answer on May 30, 2026 at 5:44 pm

    No, traits are not simply composition due the fact that the rules by which traits are “pasted” into a class are completely different.

    When using Composition, there is no chance for conflicts or methods overwriting because the composite element is a completely isolated unit (an instance of some other class) you interface with via it’s public API from within the consuming instance. Also, if you need to provide access from the consuming instance, you’d have to add proxy methods to delegate to the composite element.

    Traits on the other hand become part of the API of the very instance they are used in. They are not subsystems in the instance. They are not even instances but just a reusable boilerplate code. One benefit this provides is satisfying interfaces with a trait, as I have shown in Traits in PHP – any real world examples/best practices?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading this article about closures in which they say: all the plumbing
I am new to REST. I was reading many article about REST. Still I
I'm just reading an article about Boost.Flyweight Performance As you can see in the
Some time ago i was reading an article about new MS DBMS technology. It's
When I was reading Wikipedias's article about Double Checked Locking idiom, I'm confused about
I was reading this article about thread safety in Singletons, and it got me
I was reading Stoyan Stefanov's excellent article about JS domain sharding for image files
I was reading an article here: http://javascriptweblog.wordpress.com/2010/03/16/five-ways-to-create-objects/ It tells about five ways of creating
I have been reading countless articles about how to architect a new MVC 3
I've been wondering about this for a while after reading through an interesting article

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.