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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:07:43+00:00 2026-05-17T03:07:43+00:00

I have a bare bones ORM implementation, consisting of data mappers which load and

  • 0

I have a bare bones ORM implementation, consisting of data mappers which load and persist entities. Each mapper internally manages an identity map for all entities read from the database, so that the same entity is only loaded into memory once.

I am currently implementing lazy loading for related entities using a proxy class that loads the related data only when a property on the entity is accessed. My problem is that the proxy class is not the entity itself and is only used if the entity is loaded indirectly (via a relationship). So any === check comparing the actual entity with a proxy that loads the same entity will return false. My goal is to keep both the entities and client code unaware of the proxy objects.

The proxy class looks something like:

class EntityProxy
{
    protected $_entity;
    protected $_loader;

    public function __construct(EntityProxyLoader $loader)
    {
        $this->_loader = $loader;
    }

    protected function _load()
    {
        if (null === $this->_entity)
        {
            $this->_entity = $this->_loader->load();
            unset($this->_loader);
        }
    }

    public function __get($name)
    {
        $this->_load();
        return $this->_entity->$name;
    }

    public function __set($name, $value)
    {
        $this->_load();
        $this->_entity->$name = $value;
    }
}

And the mappers look something like:

class PersonEntityMapper
{
    // Find by primary key
    public function find($id)
    {
        if ($this->inIdentityMap($id)
        {
            return $this->loadFromIdentityMap($id);
        }

        $data = ...;  // gets the data

        $person = new Person($data);

        // Proxy placeholder for a related entity. Assume the loader is
        // supplied the information it needs in order to load the related 
        // entity.
        $person->Address = new EntityProxy(new EntityProxyLoader(...));

        $this->addToIdentityMap($id, $person);

        return $person;
    }
}

class AddressEntityMapper
{
    // Find by primary key
    public function find($id)
    {
        ...

        $address = new AddressEntity($data);

        $address->Person = new EntityProxy(new EntityProxyLoader(...));

        $this->addToIdentityMap($id, $address);

        return $address;
    }
}

If I load a “PersonEntity” record that has a related “AddressEntity”, then load that same “AddressEntity” record directly via the “AddressEntityMapper” and compare the two objects, they will not be the same (as one is a proxy that delegates). Is there any way to override PHP’s built in object comparison? Any suggestions on a better way to handle this without introducing proxy aware code into the entities and/or client code?

Also, I am aware that it would be in my benefit to adopt an existing and established ORM, but there are various issues that prevent me from doing so.

  • 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-17T03:07:43+00:00Added an answer on May 17, 2026 at 3:07 am

    Usual method is to create an equals method like you would do in Java. PHP doesn’t allow you to override == or === and I’ve never found a way to override comparators but I’ve been wrong before and it would be cool if I was wrong about this.

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

Sidebar

Related Questions

I have a bare-bones install of jenkins on my Ubuntu server that I installed
I have a bare-bones sample project here: http://dl.dropbox.com/u/7834263/ExpandingCells.zip In this project, a UITableView has
I have been trying to write a bare-bones ping scanner using Perl for internal
I have a simple ANTLR grammar, which I have stripped down to its bare
I have a bare bones servlet application. Do I store config related information in
I have stripped the following back to the bare bones, I am passing more
Suppose I have a garden-variety closure like this bare-bones sample: (let ((alpha 0) #|
I'm working on a bare-bones system in which I need to determine sometime after
broken to bare-bones scene: I have a program in c# that calls a .exe
EDIT The bare-bones version of this question is, if I have some object o

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.