{"record":{"id":"ab4eafc3aea264a6","repo":"phalcon/cphalcon","slug":"invalid-haystack","errorCode":null,"errorMessage":"Invalid haystack","messagePattern":"Invalid haystack","errorType":"exception","errorClass":"Phalcon\\Mvc\\View\\Engine\\Volt\\Exceptions\\InvalidHaystack","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/View/Engine/Volt.zep","lineNumber":169,"sourceCode":"    public function isIncluded(var needle, var haystack) -> bool\n    {\n        if unlikely null === needle {\n            let needle = \"\";\n        }\n\n        if typeof haystack == \"array\" {\n            return in_array(needle, haystack);\n        }\n\n        if typeof haystack == \"string\" {\n            if this->phpFunctionExists(\"mb_strpos\") {\n                return mb_strpos(haystack, needle) !== false;\n            }\n\n            return strpos(haystack, needle) !== false;\n        }\n\n        throw new InvalidHaystack();\n    }\n\n    /**\n     * Length filter. If an array/object is passed a count is performed otherwise a strlen/mb_strlen\n     *\n     * @param mixed item\n     *\n     * @return int\n     */\n    public function length(var item) -> int\n    {\n        if unlikely null === item {\n            let item = \"\";\n        }\n\n        if typeof item == \"object\" || typeof item == \"array\" {\n            return count(item);\n        }","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/View/Engine/Volt.zep#L151-L187","documentation":"Volt::inFilter() backs the template 'in' operator / 'in' filter: needle-in-haystack succeeds for array haystacks (in_array) and string haystacks (mb_strpos/strpos substring check); any other haystack type — null, int, float, bool, object — throws InvalidHaystack (phalcon/Mvc/View/Engine/Volt.zep:169). The operator deliberately supports only containers where membership is well-defined.","triggerScenarios":"Template {{ 'active' in user.status }} where user.status is null/int; {{ 5 in count(items) }} mixing up a count with the collection; a controller assigns null for a missing variable used with 'in'; {{ key in objectProperty }} where the property is a stdClass.","commonSituations":"Optional model relations/fields that arrive null; API responses decoded into objects rather than arrays used with 'in'; Volt templates written against arrays that later changed to iterable objects or scalars.","solutions":["Default the variable at assignment or in the template: {% set tags = tags ?? [] %} before using 'in'","Fix the operand to the actual container: {{ 'active' in user.roles }} (array), not a scalar field","Cast/normalize data in the controller before assigning to the view (e.g. (array) $dto->tags)"],"exampleFix":"// before (volt)\n{% if 'urgent' in ticket.flags %} ... {% endif %} {# flags can be null #}\n\n// after\n{% set flags = ticket.flags ?? [] %}\n{% if 'urgent' in flags %} ... {% endif %}","handlingStrategy":"type-guard","validationCode":"$haystack = $haystack ?? [];\nif (!is_array($haystack) && !is_string($haystack)) {\n    throw new \\InvalidArgumentException('Volt in-filter haystack must be array or string');\n}","typeGuard":"function acceptsHaystack(mixed $haystack): bool\n{\n    return is_array($haystack) || is_string($haystack);\n}","tryCatchPattern":null,"preventionTips":["Default nullable variables before 'in' checks: {% set xs = xs ?? [] %}","Assign normalized (array) data to views from controllers","Use 'in' only against known array/string fields"],"tags":["phalcon","volt","templates","type-validation","null-safety"],"backgroundTag":"invalid-argument-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}