{"record":{"id":"5eb65927fdf2e973","repo":"phalcon/cphalcon","slug":"resultset-returned-an-invalid-value","errorCode":null,"errorMessage":"Resultset returned an invalid value","messagePattern":"Resultset returned an invalid value","errorType":"exception","errorClass":"Phalcon\\Html\\Exceptions\\InvalidResultsetValue","httpStatus":null,"severity":"error","filePath":"phalcon/Html/Helper/Input/Select/ResultsetData.zep","lineNumber":130,"sourceCode":"    /**\n     * Walks the resultset once, building both the option map and the\n     * per-option resolved attribute map. Closures in `attributesMap`\n     * receive the current row; static values are passed through.\n     * `false` or `null` values skip the attribute entirely.\n     */\n    protected function resolve() -> void\n    {\n        var attrName, attrSpec, attrValue, attrs, option, optionAttrs,\n            optionText, optionValue, options, usingZero, usingOne;\n\n        let usingZero   = this->using[0],\n            usingOne    = this->using[1],\n            options     = [],\n            attrs       = [];\n\n        for option in this->resultset {\n            if typeof option != \"object\" && typeof option != \"array\" {\n                throw new InvalidResultsetValue();\n            }\n\n            let optionValue = this->readField(option, usingZero),\n                optionText  = this->readField(option, usingOne);\n\n            let options[optionValue] = optionText;\n\n            if !empty(this->attributesMap) {\n                let optionAttrs = [];\n\n                for attrName, attrSpec in this->attributesMap {\n                    if is_callable(attrSpec) {\n                        let attrValue = call_user_func(attrSpec, option);\n                    } else {\n                        let attrValue = attrSpec;\n                    }\n\n                    if false !== attrValue && null !== attrValue {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Html/Helper/Input/Select/ResultsetData.zep#L112-L148","documentation":"While iterating the resultset, ResultsetData::resolve() requires every row to be an object or an array so the two using columns can be read from it. A row that is a scalar, null, or resource — for example a resultset of single-column values — throws InvalidResultsetValue because no field can be read.","triggerScenarios":"The query selects a single column with a fetch mode returning scalars (PDO::FETCH_COLUMN), so every row is a string; an aggregate row that hydrates to null; a custom resultset implementation yielding scalar items.","commonSituations":"Optimizing a SELECT to one column for speed and then feeding it to the select helper; changing the DB fetch mode globally; resultsets hydrated as scalars in reporting queries.","solutions":["Select the full row (at least both using columns) so rows hydrate as objects or arrays","Map scalar rows before passing: $rows = array_map(fn($v) => ['value' => $v, 'text' => $v], $scalars)","For scalar value/text pairs, skip the resultset helper and pass a plain options array"],"exampleFix":"// before — single-column fetch, rows are strings\n$rows = $connection->query('SELECT name FROM categories', [], [\\PDO::FETCH_COLUMN]);\n\n// after — full rows hydrate as arrays\n$rows = $connection->query('SELECT id, name FROM categories')->fetchAll();","handlingStrategy":"validation","validationCode":"foreach ($resultset as $index => $row) {\n    if (!is_object($row) && !is_array($row)) {\n        throw new \\InvalidArgumentException(\n            \"Resultset row {$index} is a \" . gettype($row) . '; rows must be objects or arrays'\n        );\n    }\n}\n\n$data = new \\Phalcon\\Html\\Helper\\Input\\Select\\ResultsetData($resultset, $using, $attributesMap);","typeGuard":"/** @param mixed $row */\nfunction isSelectableRow($row): bool\n{\n    return is_object($row) || is_array($row);\n}","tryCatchPattern":"try {\n    $data = new ResultsetData($resultset, $using, $attributesMap);\n} catch (\\Phalcon\\Html\\Exceptions\\InvalidResultsetValue $e) {\n    // rows are scalars; rebuild as [value => text] options instead\n    $options = [];\n    foreach ($resultset as $row) {\n        $options[(string) $row] = (string) $row;\n    }\n    $select->setOptions($options);\n}","preventionTips":["Select at least the two using columns so rows hydrate as objects/arrays","Avoid global PDO fetch-mode changes to FETCH_COLUMN in apps that feed resultsets to helpers","Unit test select helpers with the exact query used in production"],"tags":["phalcon","html","select","resultset","row-type"],"backgroundTag":"invalid-row-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}