{"record":{"id":"9b7a833ded98d3ed","repo":"phalcon/cphalcon","slug":"invalid-event-subscriber-configuration-for-eventn","errorCode":null,"errorMessage":"Invalid event subscriber configuration for {eventName}","messagePattern":"Invalid event subscriber configuration for (.+?)","errorType":"exception","errorClass":"Phalcon\\Events\\Exceptions\\InvalidSubscriberConfiguration","httpStatus":null,"severity":"error","filePath":"phalcon/Events/Manager.zep","lineNumber":1246,"sourceCode":"        var firstParam, listener, methodName, priority;\n\n        if typeof params == \"string\" {\n            if detaching {\n                this->detach(eventName, [subscriber, params]);\n            } else {\n                this->insertHandlerEntry(\n                    eventName,\n                    [subscriber, params],\n                    1,\n                    self::DEFAULT_PRIORITY\n                );\n            }\n\n            return;\n        }\n\n        if unlikely typeof params != \"array\" {\n            throw new InvalidSubscriberConfiguration(eventName);\n        }\n\n        if !fetch firstParam, params[0] {\n            throw new InvalidSubscriberConfiguration(eventName);\n        }\n\n        if typeof firstParam == \"string\" {\n            let methodName = firstParam;\n            let priority   = self::DEFAULT_PRIORITY;\n\n            if isset params[1] {\n                let priority = params[1];\n            }\n\n            if detaching {\n                this->detach(eventName, [subscriber, methodName]);\n            } else {\n                this->insertHandlerEntry(","sourceCodeStart":1228,"sourceCodeEnd":1264,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Events/Manager.zep#L1228-L1264","documentation":"When you register a subscriber via addSubscriber()/removeSubscriber(), each value in its static getSubscribedEvents() map must be a method-name string or an array specification. processSubscriberEntry() throws InvalidSubscriberConfiguration when the value is a non-string scalar (int, float, bool) — for example an event mapped to a bare priority number.","triggerScenarios":"class AuditSubscriber implements Subscriber { public static function getSubscribedEvents(): array { return ['db:beforeQuery' => 100]; } } — the int is rejected because a priority alone does not say which method to call; $em->addSubscriber(new AuditSubscriber()) then throws for that entry.","commonSituations":"Copying Symfony's EventSubscriberInterface idiom where 'eventName' => int priority is legal — Phalcon requires the method name; a class constant used as the value being defined as an int instead of a string; refactoring configs into the map and leaving placeholder numbers.","solutions":["Give the method name: 'db:beforeQuery' => 'onBeforeQuery' (default priority)","Give method plus priority as an array: 'db:beforeQuery' => ['onBeforeQuery', 100]","For several methods on one event, use a list of pairs: 'db:beforeQuery' => [['onBeforeQuery', 100], ['logQuery', 500]]"],"exampleFix":"// before\npublic static function getSubscribedEvents(): array\n{\n    return ['db:beforeQuery' => 100]; // throws InvalidSubscriberConfiguration\n}\n\n// after\npublic static function getSubscribedEvents(): array\n{\n    return ['db:beforeQuery' => ['onBeforeQuery', 100]];\n}","handlingStrategy":"type-guard","validationCode":"function validSubscriberMap(array $map): bool\n{\n    foreach ($map as $params) {\n        if (is_string($params)) { continue; }\n        if (is_array($params) && isset($params[0])) { continue; }\n        return false;\n    }\n    return true;\n}","typeGuard":"function assertSubscriberMap(array $map): void\n{\n    foreach ($map as $event => $params) {\n        if (is_string($params)) { continue; }\n        if (!is_array($params) || !isset($params[0])) {\n            throw new InvalidArgumentException(sprintf(\n                'Bad subscriber spec for %s: need method string, [method, priority], or list of pairs; got %s',\n                $event,\n                get_debug_type($params)\n            ));\n        }\n    }\n}","tryCatchPattern":"use Phalcon\\Events\\Exceptions\\InvalidSubscriberConfiguration;\ntry {\n    $em->addSubscriber($subscriber);\n} catch (InvalidSubscriberConfiguration $e) {\n    throw new RuntimeException(get_class($subscriber) . ' has a malformed getSubscribedEvents(): ' . $e->getMessage(), 0, $e);\n}","preventionTips":["Do not port Symfony subscriber maps verbatim — Phalcon has no bare-int priority form","Add a unit test per subscriber that runs assertSubscriberMap(SubscriberClass::getSubscribedEvents())"],"tags":["phalcon","events","event-subscriber","configuration"],"backgroundTag":"event-subscriber-misconfigured","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}