{"record":{"id":"d839bf308202ffaf","repo":"phalcon/cphalcon","slug":"resultset-returned-an-invalid-value-d839bf","errorCode":null,"errorMessage":"Resultset returned an invalid value","messagePattern":"Resultset returned an invalid value","errorType":"exception","errorClass":"Phalcon\\Tag\\Exception","httpStatus":null,"severity":"error","filePath":"phalcon/Tag/Select.zep","lineNumber":283,"sourceCode":"            let usingZero = self::toStringValue(using[0]),\n                usingOne  = self::toStringValue(using[1]);\n        }\n\n        let escaper = <EscaperInterface> BaseTag::getEscaperService();\n\n        for option in iterator(resultset) {\n            if typeof using == \"array\" {\n                if typeof option == \"object\" {\n                    if method_exists(option, \"readAttribute\") {\n                        let optionValue = option->readAttribute(usingZero);\n                        let optionText = option->readAttribute(usingOne);\n                    } else {\n                        let optionValue = option->{usingZero};\n                        let optionText = option->{usingOne};\n                    }\n                } else {\n                    if unlikely typeof option != \"array\" {\n                        throw new Exception(\n                            \"Resultset returned an invalid value\"\n                        );\n                    }\n\n                    let optionValue = option[usingZero];\n                    let optionText = option[usingOne];\n                }\n\n                let optionValue = escaper->attributes(self::toStringValue(optionValue));\n                let optionText = escaper->html(self::toStringValue(optionText));\n\n                /**\n                 * If the value is equal to the option's value we mark it as\n                 * selected\n                 */\n                if typeof value == \"array\" {\n                    if in_array(optionValue, value) {\n                        let code .= self::echoOption(optionValue, true)","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Tag/Select.zep#L265-L301","documentation":"While generating options from a resultset, Tag\\Select::optionsFromResultset() iterates every row and reads the two 'using' fields. Each row must be an object (model or stdClass, optionally with readAttribute()) or an array. A row that is a scalar (string, int, null) cannot yield value/text, so rendering aborts with Phalcon\\Tag\\Exception 'Resultset returned an invalid value' (phalcon/Tag/Select.zep:283).","triggerScenarios":"Passing a Traversable/ResultsetInterface whose iterator() yields scalars: a generator that maps rows to strings, a custom resultset of single values, a cached/serialized resultset whose rows became scalars, or an iterable of nulls.","commonSituations":"Selecting a single column and mapping it to a flat list before feeding Tag::select; wrapping a resultset in a caching layer that flattens rows; array_column() output passed as data with a resultset-typed option; hydration modes that produce scalars.","solutions":["Pass the original resultset of model objects (or array rows), not a flattened/mapped scalar list.","Map rows to value=>text pairs and render with Tag::selectStatic(['city'], $options).","If rows are arrays, ensure each row contains both 'using' keys; if objects, ensure the two properties are readable."],"exampleFix":"// before\n$cities = array_column($repo->all()->toArray(), 'name'); // flat list of strings\nTag::select(['city', $cities, 'using' => ['id', 'name']]); // throws\n\n// after\n$options = [];\nforeach ($repo->all() as $row) {\n    $options[$row->id] = $row->name;\n}\nTag::selectStatic(['city'], $options);","handlingStrategy":"validation","validationCode":"$rows = is_array($data) ? $data : iterator_to_array($data);\nforeach ($rows as $row) {\n    if (!is_array($row) && !is_object($row)) {\n        throw new InvalidArgumentException('Select data rows must be arrays or objects');\n    }\n}","typeGuard":"/** @param iterable<array|object> $data */\nfunction assertSelectData(iterable $data): void\n{\n    foreach ($data as $row) {\n        if (!is_array($row) && !is_object($row)) {\n            throw new TypeError('Select data must contain rows, not scalars');\n        }\n    }\n}","tryCatchPattern":"try {\n    echo Tag::select(['city', $resultset, 'using' => ['id', 'name']]);\n} catch (\\Phalcon\\Tag\\Exception $e) {\n    $logger->warning('Falling back to empty select: ' . $e->getMessage());\n    echo '<select name=\"city\"></select>';\n}","preventionTips":["Never feed mapped/flattened scalar lists into resultset-based selects; map to value=>text pairs and use Tag::selectStatic.","Keep hydration consistent: let Tag\\Select consume model resultsets directly.","Watch caching layers that serialize resultset rows into strings."],"tags":["phalcon","tag","select","resultset","iterator","type-mismatch"],"backgroundTag":"invalid-resultset-row-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}