{"record":{"id":"9a25defc85534abc","repo":"twigphp/Twig","slug":"neither-the-property-1-s-nor-one-of-the-methods-1-s-get-1-s","errorCode":null,"errorMessage":"Neither the property \"%1$s\" nor one of the methods \"%1$s()\", \"get%1$s()\", \"is%1$s()\", \"has%1$s()\" or \"__call()\" exist and have public access in class \"%2$s\".","messagePattern":"Neither the property \"%1\\$s\" nor one of the methods \"%1\\$s\\(\\)\", \"get%1\\$s\\(\\)\", \"is%1\\$s\\(\\)\", \"has%1\\$s\\(\\)\" or \"__call\\(\\)\" exist and have public access in class \"%2\\$s\"\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/Extension/CoreExtension.php","lineNumber":1966,"sourceCode":"        } elseif (isset($cache[$class][$lcItem = strtolower($item)])) {\n            $method = $cache[$class][$lcItem];\n        } elseif (isset($cache[$class]['__call'])) {\n            $method = $item;\n            $call = true;\n        } else {\n            if ($isDefinedTest) {\n                return false;\n            }\n\n            if ($propertyNotAllowedError) {\n                throw $propertyNotAllowedError;\n            }\n\n            if ($ignoreStrictCheck || !$env->isStrictVariables()) {\n                return;\n            }\n\n            throw new RuntimeError(\\sprintf('Neither the property \"%1$s\" nor one of the methods \"%1$s()\", \"get%1$s()\", \"is%1$s()\", \"has%1$s()\" or \"__call()\" exist and have public access in class \"%2$s\".', $item, $class), $lineno, $source);\n        }\n\n        if ($sandboxed) {\n            try {\n                $env->getExtension(SandboxExtension::class)->getChecker()->checkMethodAllowed($object, $method, $lineno, $source);\n            } catch (SecurityNotAllowedMethodError $e) {\n                if ($isDefinedTest) {\n                    return false;\n                }\n\n                if ($propertyNotAllowedError) {\n                    throw $propertyNotAllowedError;\n                }\n\n                throw $e;\n            }\n        }\n","sourceCodeStart":1948,"sourceCodeEnd":1984,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Extension/CoreExtension.php#L1948-L1984","documentation":"Thrown when getAttribute() cannot resolve a property/method on an object: neither the property nor get/is/has-prefixed accessors or __call() exist with public visibility. When strict_variables is enabled (and ignoreStrictCheck is false) this becomes a RuntimeError instead of returning null.","triggerScenarios":"Accessing {{ object.foo }} or {{ object.foo() }} where the object's class lacks public property foo and public foo()/getFoo()/isFoo()/hasFoo()/__call(); common with typos, private/protected properties, or wrong object passed.","commonSituations":"Doctrine entities with private properties accessed directly; renamed getters after refactor; strict_variables=true in prod config exposing silent nulls; passing a DTO different from the expected one;magic __get removed in newer framework versions.","solutions":["Fix the property name in the template or add a public getter (getFoo/isFoo/hasFoo) to the class","Verify the object passed into the template context is the intended class","Check twig strict_variables config; keep it on in dev but ensure templates are correct rather than disabling","Use the 'defined' test ({{ object.foo is defined }}) when the attribute may legitimately be absent"],"exampleFix":"// before\nclass User { private string $name; }\n{{ user.name }}\n\n// after\nclass User { private string $name; public function getName(): string { return $this->name; } }\n{{ user.name }}","handlingStrategy":"type-guard","validationCode":"if (!method_exists($obj, 'getName') && !property_exists($obj, 'name')) { /* fix before render */ }","typeGuard":"function hasPublicAccessor(object $obj, string $prop): bool { return property_exists($obj, $prop) && (new \\ReflectionProperty($obj, $prop))->isPublic() || method_exists($obj, 'get'.ucfirst($prop)); }","tryCatchPattern":"try { $twig->render($tpl, $ctx); } catch (\\Twig\\Error\\RuntimeError $e) { if (str_starts_with($e->getMessage(), 'Neither the property')) { /* wrong object or missing getter */ } }","preventionTips":["Provide public getters for all properties used in templates","Run strict_variables=true in CI to catch template typos","Use {{ attr is defined }} test for optional attributes"],"tags":["twig","runtime-error","strict-variables","property-access"],"backgroundTag":"type-mismatch","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}