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 6386479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:01:54+00:00 2026-05-25T03:01:54+00:00

I’m writing an application with a domain model in PHP, and am wondering which

  • 0

I’m writing an application with a domain model in PHP, and am wondering which naming convention I should adopt.

Let’s say I have a Customer, having an Address within its aggregate root.

I also have a Product, having an Option within its aggregate root.

I have two alternatives:

  1. Keep aggregate roots at the root of the domain model:

    Customer
    Customer\Address
    Product
    Product\Option
    

    Pro: I can use both Customer and Product in the same namespace

    Con: Customer has to reference its own Address as Customer\Address

  2. Group all aggregate classes in the same namespace, including the aggregate root:

    Customer\Customer
    Customer\Address
    Product\Product
    Product\Option
    

    Pro: Customer can reference its address as Address

    Con: from my root domain namespace, I have to reference:

    • Customer as Customer\Customer
    • Product as Product\Product
  • 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-25T03:01:55+00:00Added an answer on May 25, 2026 at 3:01 am

    I wrote a little framework a while ago and i choose to use the first solution you propose.

    Keep aggregate roots at the root of the domain model:

    Why?

    Actually I asked myself the same question you’re asking today and after a bit of discussion with my team mates we agreed that it felt more logical not to repeat the class name in the namespace.


    Let’s see how to instanciate your classes with solution n°2

    Customer\Customer
    Customer\Address
    

    You will have to write :

    $customer = new Customer\Customer();
    $address = new Customer\Address();
    

    You can see the repetition right? It kind of doesn’t feel right to me.
    In my opinion it’s like writing

    $customer->getCustomerId();
    

    Why repeat Customer in the method name? We know it’s the customer’s id since we’re using a Customer object.

    Another “bad thing” with this model is the impossibility to use reserved keyword as class name.

    For exemple, using the pear convention you could have had the class

    Customer_Abstract
    

    Located at Customer/Abstract.php which is ok to me but if you try to translate it using namespace you will have

    namespace Customer;
    
    class Abstract {}
    

    which results in a fatal error. So again you will have to repeat the domain in the class name :

    namespace Customer;
    
    class AbstractCustomer {}
    
    $customer = new Customer\AbstractCustomer();
    

    Now let’s see how to instanciate your classes with solution n°1

    Customer
    Customer\Address
    

    You will write :

    $customer = new Customer();
    $address = new Customer\Address();
    

    We don’t have to repeat Customer twice anymore to instanciate the Customer class. However it is still clear that Address is related to Customer.

    That’s why I choose to use this model.

    EDIT : Zend Framework 2 use this convention too

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.