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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:09:41+00:00 2026-05-27T17:09:41+00:00

I have been implementing value objects as custom DBAL types in Doctrine 2 and

  • 0

I have been implementing value objects as custom DBAL types in Doctrine 2 and it’s been working OK. However I have been wondering if this is the best way. I’ve thought about using the Post Load listener to instantiate the Value Objects. Also instantiating them through Entity accessors when requested, the advantage with the latter would be that I would not instantiate more objects than I need.

My question is: which method is best? Or is there a better way to do it? Are there any gotchas or unreasonable performance hits with the above?

  • 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-27T17:09:42+00:00Added an answer on May 27, 2026 at 5:09 pm

    IMHO, both approaches are equally valuable, while waiting for native support for value objects.

    I personally favor the second approach (instantiating them through accessors when requested) for two reasons:

    • As you mentioned, it offers better performance as the conversion is only done when needed;
    • It decouples your application from Doctrine dependency: you’re writing less code that is Doctrine-specific.

    An example of this approach:

    class User
    {
        protected $street;
        protected $city;
        protected $country;
    
        public function setAddress(Address $address)
        {
            $this->street  = $address->getStreet();
            $this->city    = $address->getCity();
            $this->country = $address->getCountry();
        }
    
        public function getAddress()
        {
            return new Address(
                $this->street,
                $this->city,
                $this->country
            );
        }
    }
    

    This code will be fairly easy to refactor when Doctrine will offer native VO support.

    About custom mapping types, I do use them as well, for single-field VO (Decimal, Point, Polygon, …) but would tend to reserve them for general-purpose, reusable types that can be used across multiple projects, not for project-specific single-field VO where I would favor the approach above.

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

Sidebar

Related Questions

I have been working on implementing the first 6 functions of the NSComparisonMethods protocol
We've been working on implementing timezone support for our Web app. This great SO
I have been tasked with implementing a PKI library in C# for a company
I have been looking at using TDD and implementing proper testing (only just started
I have been studying SOAP and WSDL in preparation for implementing a web service.
I am implementing a system where I need real-time updates. I have been looking
I have been working on a web services related project for about the last
I have been implementing a class which class extends ArrayAdapter and implements Filterable. The
I've been implementing this little game idea, which is (somehow?) similar to Conway's Game
I have been implementing AES onto my website for security and I have ran

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.