Skip to content

Fix Framework\Factory sharing one singleton across subclasses #613

Closed

Description

@jonathanbossenger

Part of #302. Blocks #307.

What problem does this address?

Framework\Factory resolves self::$instance on the abstract base class, so Factory\Message::get_instance() and Factory\Notification::get_instance() return the same object. Hydrating both model types in one request (which every notification query does, since a notification is messages JOIN queue) calls make() on the wrong class.

What is your proposed solution?

Store instances per class, e.g. static::$instances[ static::class ], and add a unit test asserting the two factories return distinct instances of the correct class.

Activity

  1. added this to the 0.3.0 milestone on Oct 16, 2026
  2. added
    bugSomething isn't working
    [Scope] ModelDefinition of the data used in the WP Notify project
    phpPull requests that update Php code
    on Oct 16, 2026
  3. huzaifaalmesbah commented on Oct 16, 2026

    @huzaifaalmesbah
    Member

    Hi @jonathanbossenger, I'd like to work on this one.

    I've reproduced it: on develop, Factory\Notification::get_instance() returns the Factory\Message instance, because get_instance() stores the instance in self::$instance on the abstract base class.

    My plan is to keep one instance per subclass in a static::$instances[ static::class ] map, and add a PHPUnit test that checks each factory returns its own class, that two factories never return the same object, and that repeat calls return the same object. I'll open a PR shortly.

  4. added a commit that references this issue on Nov 3, 2026
    52e27c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Scope] ModelDefinition of the data used in the WP Notify projectbugSomething isn't workinghas-prThe issue has a linked PRphpPull requests that update Php code

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions