{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Container/Container.php#L1193-L1229","documentation":"BindingResolutionException from buildSelfBuildingInstance() when a concrete implementing the SelfBuilding contract does not declare the required newInstance() method. The SelfBuilding path delegates construction to newInstance(); without it the contract cannot be honored.","triggerScenarios":"A class implements Illuminate\\Contracts\\Container\\SelfBuilding (or is_a SelfBuilding::class) but omits the newInstance method; a class was renamed/changed and the method was dropped; partial implementation of the contract.","commonSituations":"Adopting the SelfBuilding feature without completing the contract; IDE-assisted refactor deleting an 'unused' newInstance method; copy-paste of a SelfBuilding class with the method stripped.","solutions":["Add a public newInstance(\\Closure $container, array $parameters) method returning an instance.","If SelfBuilding behavior is not intended, remove the interface/extends so the container builds the class normally.","Verify method visibility - newInstance must be public and callable via the container."],"exampleFix":"// before\nclass ReportFactory implements SelfBuilding\n{\n    // missing newInstance\n}\n// after\nclass ReportFactory implements SelfBuilding\n{\n    public function newInstance(Container $container, array $parameters = []): static\n    {\n        return new static(...$parameters);\n    }\n}","handlingStrategy":"type-guard","validationCode":"if (is_a($concrete, \\Illuminate\\Contracts\\Container\\SelfBuilding::class, true)\n    && ! method_exists($concrete, 'newInstance')) {\n    throw new RuntimeException(\"SelfBuilding class [$concrete] must implement newInstance().\");\n}\n$container->make($concrete);","typeGuard":"function selfBuilderIsComplete(string $class): bool\n{\n    return is_a($class, \\Illuminate\\Contracts\\Container\\SelfBuilding::class, true)\n        && method_exists($class, 'newInstance');\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\n\ntry {\n    $instance = $container->make($class);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'No newInstance method')) {\n        // add newInstance() or drop the SelfBuilding interface\n    }\n    throw $e;\n}","preventionTips":["When adopting SelfBuilding, scaffold newInstance() via an IDE live template.","Static-analysis contract completeness so partial implementations fail at CI time.","Avoid deleting newInstance() during refactors; mark it @internal/@required in docblocks."],"tags":["container","self-building","di","contract"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}