{"record":{"id":"2b1f544c237cb452","repo":"yiisoft/yii2","slug":"the-user-part-of-ownership-must-be-an-integer-st","errorCode":null,"errorMessage":"The user part of $ownership must be an integer, string, or null.","messagePattern":"The user part of \\$ownership must be an integer, string, or null\\.","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseFileHelper.php","lineNumber":1014,"sourceCode":"                $group = ArrayHelper::getValue($ownership, $ownershipIsIndexed ? 1 : 'group');\n            } else {\n                throw new InvalidArgumentException('$ownership must be an integer, string, array, or null.');\n            }\n        }\n\n        if ($mode !== null) {\n            if (!is_int($mode)) {\n                throw new InvalidArgumentException('$mode must be an integer or null.');\n            }\n            if (!chmod($path, $mode)) {\n                throw new Exception('Unable to change mode of \"' . $path . '\" to \"0' . decoct($mode) . '\".');\n            }\n        }\n        if ($user !== null && $user !== '') {\n            if (is_numeric($user)) {\n                $user = (int) $user;\n            } elseif (!is_string($user)) {\n                throw new InvalidArgumentException('The user part of $ownership must be an integer, string, or null.');\n            }\n            if (!chown($path, $user)) {\n                throw new Exception('Unable to change user ownership of \"' . $path . '\" to \"' . $user . '\".');\n            }\n        }\n        if ($group !== null && $group !== '') {\n            if (is_numeric($group)) {\n                $group = (int) $group;\n            } elseif (!is_string($group)) {\n                throw new InvalidArgumentException('The group part of $ownership must be an integer, string or null.');\n            }\n            if (!chgrp($path, $group)) {\n                throw new Exception('Unable to change group ownership of \"' . $path . '\" to \"' . $group . '\".');\n            }\n        }\n    }\n}\n","sourceCodeStart":996,"sourceCodeEnd":1032,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseFileHelper.php#L996-L1032","documentation":"Inside changeOwnership(), the extracted 'user' part must be numeric-coercible, a string, or null; an array or object (e.g. pulled out of the associative ownership array) hits the elseif !is_string branch and throws InvalidArgumentException before chown() is called. The defect is in how the ownership array/string was assembled, not in the environment.","triggerScenarios":"['user' => ['name' => 'www-data']] — a nested array under the 'user' key; ArrayHelper::getValue($ownership, 'user') returning an array default; indexed form [0 => ['uid' => 33], 1 => 33] where the user slot holds an array.","commonSituations":"YAML config producing nested maps for ownership; forwarding unchecked request/config data into the ownership argument; config schemas that allow both scalar and structured forms and default to the structured one.","solutions":["Flatten config to scalar user/group values ('user' => 'www-data').","Validate the extracted user before the call: is_numeric($user) || is_string($user) || $user === null.","Cast numeric strings to int and pass plain strings otherwise."],"exampleFix":"// before\n\\yii\\helpers\\FileHelper::changeOwnership($file, ['user' => ['name' => 'www-data']]);\n\n// after\n\\yii\\helpers\\FileHelper::changeOwnership($file, ['user' => 'www-data']);","handlingStrategy":"type-guard","validationCode":"$user = is_array($ownership) ? ($ownership['user'] ?? null) : $ownership;\nif (!(is_numeric($user) || is_string($user) || $user === null)) {\n    throw new \\InvalidArgumentException('Ownership user part must be scalar');\n}","typeGuard":"/** @param mixed $user */\nfunction isUserPart($user): bool\n{\n    return $user === null || $user === '' || is_numeric($user) || is_string($user);\n}","tryCatchPattern":null,"preventionTips":["Flatten ownership config to scalar 'user' and 'group' values.","Reject structured/nested ownership values at the config-loading boundary.","Document the ownership parameter contract (int|string|array|null) wherever wrappers expose it."],"tags":["ownership","type-validation","invalid-argument","yii2"],"backgroundTag":"wrong-argument-type","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}