You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix Framework\Factory sharing one singleton across subclasses #613
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.
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.
Activity
huzaifaalmesbah commentedon Oct 16, 2026
Hi @jonathanbossenger, I'd like to work on this one.
I've reproduced it: on
develop,Factory\Notification::get_instance()returns theFactory\Messageinstance, becauseget_instance()stores the instance inself::$instanceon 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.Framework: Store one Factory instance per subclass (WordPress#624)