{"record":{"id":"0c27e3f16728e3dc","repo":"phalcon/cphalcon","slug":"the-parameter-must-be-an-instance-of-collection-or","errorCode":null,"errorMessage":"The parameter must be an instance of Collection or DiInterface","messagePattern":"The parameter must be an instance of Collection or DiInterface","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"phalcon/Auth/Internal/ContainerResolver.zep","lineNumber":42,"sourceCode":" * Intent is Container-first; the legacy Di is supported \"with provisions\":\n * definitions must be pre-registered (no autowiring), the one exception\n * being the fresh path, which lets Di build an unregistered but existing\n * class via its class builder.\n *\n * All legacy-Di failures are normalized to Phalcon\\Container\\Exceptions so\n * callers and userland catch a single exception family.\n */\nfinal class ContainerResolver\n{\n    /**\n     * Validates that the value is a supported container.\n     *\n     * @throws TypeError\n     */\n    public static function ensureContainer(var container) -> void\n    {\n        if (!(container instanceof Collection) && !(container instanceof DiInterface)) {\n            throw new TypeError(\n                \"The parameter must be an instance of Collection or DiInterface\"\n            );\n        }\n    }\n\n    /**\n     * Resolves the first candidate service name that the container can\n     * provide, as a shared instance. Used for framework services (request,\n     * cookies, session) whose container key may vary between application\n     * setups.\n     *\n     * @param list<string> $candidates\n     *\n     * @throws ContainerException\n     */\n    public static function requireService(var container, array candidates, string context) -> object\n    {\n        self::ensureContainer(container);","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Auth/Internal/ContainerResolver.zep#L24-L60","documentation":"The Auth component's ContainerResolver::ensureContainer() only accepts two container types: Phalcon\\Contracts\\Container\\Service\\Collection (the new Phalcon Container) or Phalcon\\Di\\DiInterface (the legacy DI). Anything else - an array, a string, null, or a foreign container (e.g. a PSR-11 implementation) - triggers a native TypeError. This guard runs at the top of every container-resolution helper in the Auth internals.","triggerScenarios":"Passing an invalid container anywhere the Auth component expects one: ManagerFactory constructor, ManagerFactory::load($config) with a wrong container object, or guard options where the container is supplied as an array config value; e.g. new ManagerFactory($hasher, ['di' => []]).","commonSituations":"Passing a PSR-11 container (League\\Container, PHP-DI) assuming compatibility; passing the raw config array instead of the DI instance; passing null and expecting lazy setup; refactoring from Di to another container during a framework migration.","solutions":["Pass a Phalcon\\Di\\Di instance (typically the shared $di) or a Phalcon\\Container\\Container collection to the Auth factory/manager","Fetch the correct object explicitly: $di = Di::getDefault(); then hand $di to ManagerFactory","If you use a foreign container, bridge it by registering the needed services (session, cookies, request) into a Phalcon Di first"],"exampleFix":"// before\n$factory = new ManagerFactory($hasher, $configArray);\n\n// after\n$di = \\Phalcon\\Di\\Di::getDefault();\n$factory = new ManagerFactory($hasher, $di);","handlingStrategy":"type-guard","validationCode":"if (!$container instanceof \\Phalcon\\Di\\DiInterface\n    && !$container instanceof \\Phalcon\\Contracts\\Container\\Service\\Collection) {\n    throw new TypeError('Expected Phalcon Di or Container collection');\n}","typeGuard":"function isPhalconContainer($container): bool\n{\n    return $container instanceof \\Phalcon\\Di\\DiInterface\n        || $container instanceof \\Phalcon\\Contracts\\Container\\Service\\Collection;\n}","tryCatchPattern":null,"preventionTips":["Always source the container from Di::getDefault() or your bootstrap's single container factory","Do not pass PSR-11 containers directly - register the needed services into a Phalcon Di instead","Type-hint your own wrappers with DiInterface so misuse is caught statically"],"tags":["auth","dependency-injection","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}