{"record":{"id":"374e67b9978e9f69","repo":"symfony/http-kernel","slug":"controller-attributes-cannot-contain-non-scalar-non-null","errorCode":null,"errorMessage":"Controller attributes cannot contain non-scalar/non-null values (value for key \"%s\" is not a scalar or null).","messagePattern":"Controller attributes cannot contain non-scalar/non-null values \\(value for key \"(.+?)\" is not a scalar or null\\)\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Fragment/FragmentUriGenerator.php","lineNumber":83,"sourceCode":"        // we need to sign the absolute URI, but want to return the path only.\n        $fragmentUri = $sign || $absolute ? $request->getUriForPath($path) : $request->getBaseUrl().$path;\n\n        if (!$sign) {\n            return $fragmentUri;\n        }\n\n        $fragmentUri = $this->signer->sign($fragmentUri, $this->expiration);\n\n        return $absolute ? $fragmentUri : substr($fragmentUri, \\strlen($request->getSchemeAndHttpHost()));\n    }\n\n    private function checkNonScalar(array $values): void\n    {\n        foreach ($values as $key => $value) {\n            if (\\is_array($value)) {\n                $this->checkNonScalar($value);\n            } elseif (!\\is_scalar($value) && null !== $value) {\n                throw new \\LogicException(\\sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key \"%s\" is not a scalar or null).', $key));\n            }\n        }\n    }\n}\n","sourceCodeStart":65,"sourceCodeEnd":88,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Fragment/FragmentUriGenerator.php#L65-L88","documentation":"FragmentUriGenerator::checkNonScalar() throws LogicException when controller attributes contain arrays nested with non-scalar, non-null values. Fragment attributes are serialized into the URL query string, so only scalars and null survive the round trip.","triggerScenarios":"Passing a ControllerReference whose attributes include objects, resources, or nested arrays holding such values, e.g. generate(new ControllerReference('App\\Controller::show', ['entity' => $object])).","commonSituations":"Passing entities or value objects as fragment controller arguments; forgetting that URL generation flattens attributes to query parameters.","solutions":["Pass only scalars (int, string, bool, float) or null as attributes; pass identifiers (e.g. entity id) instead of objects.","Remove the offending attribute or fetch the object inside the fragment controller.","Pass $strict = false to skip the check only if you understand the value will be mangled in the URL."],"exampleFix":"// before\n$ref = new ControllerReference('App\\Controller\\FragmentController::show', ['product' => $product]);\n// after\n$ref = new ControllerReference('App\\Controller\\FragmentController::show', ['productId' => $product->getId()]);","handlingStrategy":"validation","validationCode":"foreach ($attributes as $k => $v) { if (!is_scalar($v) && null !== $v) { throw new \\InvalidArgumentException(\"Attribute '$k' must be scalar or null\"); } }","typeGuard":"function hasOnlyScalarAttributes(array $attrs): bool { foreach ($attrs as $v) { if (is_array($v)) { return hasOnlyScalarAttributes($v); } if (!is_scalar($v) && null !== $v) { return false; } } return true; }","tryCatchPattern":null,"preventionTips":["Pass IDs, not entities, to fragment controllers","Validate ControllerReference attributes in a dev-mode listener","Remember attributes become URL query parameters"],"tags":["php","symfony","fragment","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}