{"record":{"id":"001312601262a371","repo":"moodle/moodle","slug":"constructor-accepts-a-string-or-an-array-as-an-argument","errorCode":null,"errorMessage":"Constructor accepts a string or an array as an argument.","messagePattern":"Constructor accepts a string or an array as an argument\\.","errorType":"validation","errorClass":"InvalidArnException","httpStatus":null,"severity":"error","filePath":"public/lib/aws-sdk/src/Arn/Arn.php","lineNumber":66,"sourceCode":"                } else {\n                    // If there are < 5 components, put remainder in current\n                    // component.\n                    $data[key($data)] = substr($string, $lastDelim);\n                }\n            }\n        }\n\n        return $data;\n    }\n\n    public function __construct($data)\n    {\n        if (is_array($data)) {\n            $this->data = $data;\n        } elseif (is_string($data)) {\n            $this->data = static::parse($data);\n        } else {\n            throw new InvalidArnException('Constructor accepts a string or an'\n                . ' array as an argument.');\n        }\n\n        static::validate($this->data);\n    }\n\n    public function __toString()\n    {\n        if (!isset($this->string)) {\n            $components = [\n                $this->getPrefix(),\n                $this->getPartition(),\n                $this->getService(),\n                $this->getRegion(),\n                $this->getAccountId(),\n                $this->getResource(),\n            ];\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/aws-sdk/src/Arn/Arn.php#L48-L84","documentation":"Arn::__construct() only accepts a string (which it parses) or an array of already-parsed components; any other type (null, int, object) throws InvalidArnException. It is a constructor input-type guard.","triggerScenarios":"Passing null (e.g. from an unset config value or failed lookup) into new Arn(...), passing an integer or object instead of a string/array.","commonSituations":"Config values that resolve to null, passing the result of a function that returns mixed, typos where the variable holding the ARN string was never assigned.","solutions":["Ensure the value is a string ARN or an associative array of parsed components before constructing.","Coerce with (string) if it's a scalar, after verifying it isn't null.","Check upstream config/env for the missing ARN value.","Type-check: if (!is_string($arn) && !is_array($arn)) fail early in your code."],"exampleFix":"// before\n$arn = new Arn($config['role_arn']); // may be null\n// after\nif (!is_string($config['role_arn'] ?? null)) {\n    throw new \\Exception('role_arn must be a string');\n}\n$arn = new Arn($config['role_arn']);","handlingStrategy":"type-guard","validationCode":"if (!is_string($data) && !is_array($data)) throw new \\Exception('ARN must be string or array');","typeGuard":"function isArnInput($v): bool { return is_string($v) || is_array($v); }","tryCatchPattern":"try { $arn = new Arn($data); } catch (InvalidArnException $e) { // log type of $data, fix upstream config }","preventionTips":["Assert config values are non-null strings at boot","Use ?? '' defaults plus explicit emptiness checks","Type-hint parameters in your own code (string $arn)"],"tags":["aws-sdk","arn","php","type-error"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}