{"record":{"id":"176ba9395aa277ad","repo":"yiisoft/yii2","slug":"the-group-part-of-ownership-must-be-an-integer-s","errorCode":null,"errorMessage":"The group part of $ownership must be an integer, string or null.","messagePattern":"The group 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":1024,"sourceCode":"            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":1006,"sourceCodeEnd":1032,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseFileHelper.php#L1006-L1032","documentation":"The mirror of the user-side check inside changeOwnership(): the extracted 'group' part must be numeric-coercible, a string, or null. An array or object in the group slot throws InvalidArgumentException before chgrp() runs. It reports a malformed ownership argument, not a filesystem failure.","triggerScenarios":"['group' => ['gid' => 33]]; the string form 'user:' combined with a downstream lookup that injects an array; indexed form [0 => 'www-data', 1 => ['gid' => 33]] with an array in the group slot.","commonSituations":"Structured config (YAML maps) for group ownership; ownership values merged from multiple config sources where one side supplies an array; API-driven ownership data with unknown shape.","solutions":["Flatten config so 'group' maps to a scalar (name or gid).","Validate the extracted group: is_numeric($group) || is_string($group) || $group === null.","Cast numeric strings to int before the call."],"exampleFix":"// before\n\\yii\\helpers\\FileHelper::changeOwnership($file, ['user' => 'www-data', 'group' => ['gid' => 33]]);\n\n// after\n\\yii\\helpers\\FileHelper::changeOwnership($file, ['user' => 'www-data', 'group' => 33]);","handlingStrategy":"type-guard","validationCode":"$group = is_array($ownership) ? ($ownership['group'] ?? null) : null;\nif (!(is_numeric($group) || is_string($group) || $group === null)) {\n    throw new \\InvalidArgumentException('Ownership group part must be scalar');\n}","typeGuard":"/** @param mixed $group */\nfunction isGroupPart($group): bool\n{\n    return $group === null || $group === '' || is_numeric($group) || is_string($group);\n}","tryCatchPattern":null,"preventionTips":["Keep the 'group' key in ownership config a scalar (name or gid).","Validate the whole ownership structure once, at config load, not at each call site.","Add config schema tests asserting scalar types for user/group."],"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"}