{"record":{"id":"4464d3d14ef9a0df","repo":"phalcon/cphalcon","slug":"the-using-parameter-requires-exactly-two-values","errorCode":null,"errorMessage":"The 'using' parameter requires exactly two values","messagePattern":"The 'using' parameter requires exactly two values","errorType":"exception","errorClass":"Phalcon\\Html\\Exceptions\\UsingRequiresTwoValues","httpStatus":null,"severity":"error","filePath":"phalcon/Html/Helper/Input/Select/ResultsetData.zep","lineNumber":61,"sourceCode":"    protected resultset;\n\n    /**\n     * @var array\n     */\n    protected using = [];\n\n    /**\n     * @param ResultsetInterface resultset\n     * @param array              using\n     * @param array              attributesMap\n     */\n    public function __construct(\n        <ResultsetInterface> resultset,\n        array using,\n        array attributesMap = []\n    ) {\n        if unlikely count(using) !== 2 {\n            throw new UsingRequiresTwoValues();\n        }\n\n        let this->resultset     = resultset;\n        let this->using         = using;\n        let this->attributesMap = attributesMap;\n    }\n\n    /**\n     * Returns per-option attribute maps, keyed by option value.\n     *\n     * @return array\n     */\n    public function getAttributes() -> array\n    {\n        if null === this->resolvedAttributes {\n            this->resolve();\n        }\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Html/Helper/Input/Select/ResultsetData.zep#L43-L79","documentation":"ResultsetData drives the Select helper from a Phalcon Resultset. Its constructor requires the $using array to hold exactly two entries — the column used for option values and the column used for option text — and throws UsingRequiresTwoValues immediately when count($using) !== 2.","triggerScenarios":"Passing a resultset to the select helper with using values like ['id'] (one column) or ['id', 'name', 'label'] (three columns); building the using list dynamically from configuration and ending up with an unexpected count.","commonSituations":"The classic 'using' option of Phalcon select inputs configured with the wrong column count; changing a query's selected columns and forgetting to update the value/text pair.","solutions":["Pass exactly two column names: ['id', 'name']","Validate count($using) === 2 before constructing the select helper","If you need extra per-option data, use the attributesMap or a separate lookup instead of a third using entry"],"exampleFix":"// before\n$select->setUsing(['id', 'name', 'label']); // three entries\n\n// after\n$select->setUsing(['id', 'name']);","handlingStrategy":"validation","validationCode":"if (count($using) !== 2) {\n    throw new \\InvalidArgumentException(\n        'The using parameter requires exactly two columns: [valueColumn, textColumn]'\n    );\n}\n\n$data = new \\Phalcon\\Html\\Helper\\Input\\Select\\ResultsetData($resultset, $using, $attributesMap);","typeGuard":"/** @param mixed $using */\nfunction isUsingPair($using): bool\n{\n    return is_array($using) && count($using) === 2;\n}","tryCatchPattern":"try {\n    $data = new ResultsetData($resultset, $using, $attributesMap);\n} catch (\\Phalcon\\Html\\Exceptions\\UsingRequiresTwoValues $e) {\n    // misconfiguration: log and fall back to the first two columns\n    error_log($e->getMessage());\n    $data = new ResultsetData($resultset, array_slice($using, 0, 2), $attributesMap);\n}","preventionTips":["Always configure selects with exactly ['valueColumn', 'textColumn']","When using is built from config, validate its count during config loading","Cover select configuration in a smoke test that renders every select"],"tags":["phalcon","html","select","resultset","argument-count"],"backgroundTag":"invalid-argument-count","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}