{"record":{"id":"f85cdc8660fc8f0f","repo":"phalcon/cphalcon","slug":"the-index-does-not-exist-in-the-row","errorCode":null,"errorMessage":"The index does not exist in the row","messagePattern":"The index does not exist in the row","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\IndexNotInRow","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Row.zep","lineNumber":56,"sourceCode":"     *\n     * @param string|int $index\n     */\n    public function offsetExists(mixed index) -> bool\n    {\n        return property_exists(this, index);\n    }\n\n    /**\n     * Gets a record in a specific position of the row\n     *\n     * @param string|int index\n     *\n     * @return string|ModelInterface\n     */\n    public function offsetGet(mixed index) -> mixed\n    {\n        if !property_exists(this, index) {\n            throw new IndexNotInRow();\n        }\n\n        return this->{index};\n    }\n\n    /**\n     * Rows cannot be changed. It has only been implemented to meet the definition of the ArrayAccess interface\n     *\n     * @param string|int offsetSet\n     * @param ModelInterface value\n     */\n    public function offsetSet(mixed offset, mixed value) -> void\n    {\n        throw new RowIsImmutable();\n    }\n\n    /**\n     * Rows cannot be changed. It has only been implemented to meet the definition of the ArrayAccess interface","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Row.zep#L38-L74","documentation":"Phalcon\\Mvc\\Model\\Row is the read-only result object the ORM returns for queries that select partial columns or computed expressions (e.g. via ModelsManager::createQuery with a column list). It implements ArrayAccess, and offsetGet() throws IndexNotInRow when the requested key is not a property on the row - i.e. the key was never selected or aliased into the result set. Only the exact column names/aliases present in the SELECT are addressable.","triggerScenarios":"Calling $row['key'] (or $row->readAttribute('key')) on a Row where 'key' was not part of the SELECT clause; using a typo'd or case-mismatched alias (aliases are case-sensitive); accessing a column after renaming it in the DB without updating the query; calling $row['id'] on a raw/phalcon-db result row forwarded through Model::Row.","commonSituations":"Partial SELECT queries ('SELECT inv_title FROM ...') followed by code that reads other model attributes; queries with expression aliases where code uses the raw column name instead of the alias; switching hydration from Models to Row objects during refactoring; joins where the developer assumes all table columns exist on the row.","solutions":["Add the missing column (or an alias for it) to the SELECT clause of the query producing the Row","Guard the access with property_exists($row, 'key') or isset($row['key']) before reading","If you need full model behavior, select the model itself (SELECT * FROM Model or select the entity) instead of bare columns so you get a Model instance rather than Row","Dump the available keys once (get_object_vars($row) or iterator_to_array($row)) to see exactly what the row contains and fix the key name"],"exampleFix":"// before\n$title = $row['inv_title'];\n$price = $row['inv_price']; // throws IndexNotInRow - not selected\n\n// after: select it, or guard it\n$queries = $modelsManager->createQuery(\n    'SELECT inv_title, inv_price FROM Invoices WHERE inv_id = :id:'\n);\n// ...\n$price = property_exists($row, 'inv_price') ? $row['inv_price'] : null;","handlingStrategy":"validation","validationCode":"// Before reading a key off a partial-select result row\nuse Phalcon\\Mvc\\Model\\Row;\n\nfunction rowValue(Row $row, string $key, mixed $default = null): mixed\n{\n    return property_exists($row, $key) ? $row->{$key} : $default;\n}\n\n$price = rowValue($row, 'inv_price');","typeGuard":"function rowHas(Row $row, string $key): bool\n{\n    return property_exists($row, $key);\n}","tryCatchPattern":"try {\n    $value = $row['inv_price'];\n} catch (\\Phalcon\\Mvc\\Model\\Exceptions\\IndexNotInRow $e) {\n    $value = null; // or log which key was missing: inspect get_object_vars($row)\n}","preventionTips":["Keep a single source of truth listing selected columns, and read only those keys from Row results","Prefer hydrating to arrays for reporting queries where callers access arbitrary keys","Add a debug helper that dumps get_object_vars($row) when a key lookup fails during development"],"tags":["phalcon","orm","arrayaccess","result-row","undefined-key"],"backgroundTag":"undefined-array-key","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}