{"id":"1c530a131fcd65f2","repo":"laravel/framework","slug":"no-newinstance-method-exists-for-concrete","errorCode":null,"errorMessage":"No newInstance method exists for [$concrete].","messagePattern":"No newInstance method exists for \\[\\$concrete\\]\\.","errorType":"exception","errorClass":"BindingResolutionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/Container.php","lineNumber":1211,"sourceCode":"\n        return $instance;\n    }\n\n    /**\n     * Instantiate a concrete instance of the given self building type.\n     *\n     * @template TClass of object\n     *\n     * @param  object{'newInstance': \\Closure(static, array): TClass|class-string<TClass>}  $concrete\n     * @param  \\ReflectionClass  $reflector\n     * @return TClass\n     *\n     * @throws \\Illuminate\\Contracts\\Container\\BindingResolutionException\n     */\n    protected function buildSelfBuildingInstance($concrete, $reflector)\n    {\n        if (! method_exists($concrete, 'newInstance')) {\n            throw new BindingResolutionException(\"No newInstance method exists for [$concrete].\");\n        }\n\n        $this->buildStack[] = $concrete;\n\n        $instance = $this->call([$concrete, 'newInstance']);\n\n        array_pop($this->buildStack);\n\n        $this->fireAfterResolvingAttributeCallbacks(\n            $reflector->getAttributes(), $instance\n        );\n\n        return $instance;\n    }\n\n    /**\n     * Resolve all of the dependencies from the ReflectionParameters.\n     *","sourceCodeStart":1193,"sourceCodeEnd":1229,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Container/Container.php#L1193-L1229","documentation":"Thrown by Container::buildSelfBuildingInstance when a class implements the SelfBuilding contract (so the container delegates instantiation to it) but the class does not declare the required newInstance method. SelfBuilding types are expected to expose newInstance(\\Illuminate\\Container\\Container, array) so the container can call it to build the instance.","triggerScenarios":"A class implements Illuminate\\Contracts\\Container\\SelfBuilding but the developer removed or renamed the newInstance method, or declared it private/static/wrongly-typed so method_exists returns false (note: method_exists checks visibility-correct existence).","commonSituations":"Custom value objects/DTOs that opt into SelfBuilding for container-managed construction; refactoring a SelfBuilding class and forgetting newInstance; partial copy of an interface implementation.","solutions":["Add a public instance method `public function newInstance(Container $container, array $parameters = []): static` (or matching signature) to the SelfBuilding class.","If you no longer want container-managed construction, remove the SelfBuilding interface from the class.","Ensure the method is public and not static-only — method_exists must see an instance-callable method."],"exampleFix":"// before\nclass Money implements \\Illuminate\\Contracts\\Container\\SelfBuilding\n{\n    // newInstance missing\n}\n\n// after\nclass Money implements \\Illuminate\\Contracts\\Container\\SelfBuilding\n{\n    public function newInstance(\\Illuminate\\Container\\Container $container, array $parameters = []): static\n    {\n        return new self($parameters['amount'] ?? 0);\n    }\n}","handlingStrategy":"validation","validationCode":"if (is_a($class, \\Illuminate\\Contracts\\Container\\SelfBuilding::class, true)\n    && ! method_exists($class, 'newInstance')) {\n    throw new \\LogicException(\"{$class} implements SelfBuilding but has no newInstance method\");\n}\napp()->make($class);","typeGuard":"function hasSelfBuildingFactory(string $class): bool\n{\n    return ! is_a($class, \\Illuminate\\Contracts\\Container\\SelfBuilding::class, true)\n        || method_exists($class, 'newInstance');\n}","tryCatchPattern":null,"preventionTips":["Pair SelfBuilding with a contract test asserting newInstance exists.","Remove SelfBuilding if you no longer need container-managed construction.","Use IDE templates for SelfBuilding classes."],"tags":["container","self-building","di","contracts"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}