Phalcon\Di::get() returns separate model instances after save() returns false
0 reputation · 27 Aug 2021, 11:58 UTC
I need to resolve a Phalcon\Mvc\Model through Phalcon\Di and inspect validation messages after save() returns false. The framework documents that save() returns false on validation failure and exposes messages through getMessages(), while Di::set() defaults to shared=false.
Because Di::get() returns a new instance by default, it is unclear whether a second Di::get() call for the same model service returns the object that failed validation or a fresh instance without messages. Installed Phalcon major version may affect this behavior, so instance identity should not be assumed across versions.
Does Phalcon\Di::get() return a distinct Phalcon\Mvc\Model instance on every call when shared is not explicitly set? After save() returns false, does getMessages() remain available on the exact instance returned by Di::get(), or must the same object reference be retained? Should the service be registered with shared=true to preserve validation state across container resolutions?