Skip to content

Commit

Permalink
fix: primitive variadic class make (#43985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel authored Sep 5, 2022
1 parent 0c18029 commit 150bd1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,10 @@ protected function resolvePrimitive(ReflectionParameter $parameter)
return $parameter->getDefaultValue();
}

if ($parameter->isVariadic()) {
return [];
}

$this->unresolvablePrimitive($parameter);
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Container/ContainerResolveNonInstantiableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public function testResolvingNonInstantiableWithVariadicRemovesWiths()
$this->assertCount(0, $parent->child->objects);
$this->assertSame(42, $parent->i);
}

public function testResolveVariadicPrimitive()
{
$container = new Container;
$parent = $container->make(VariadicPrimitive::class);

$this->assertSame($parent->params, []);
}
}

interface TestInterface
Expand Down Expand Up @@ -73,3 +81,16 @@ public function __construct(TestInterface ...$objects)
$this->objects = $objects;
}
}

class VariadicPrimitive
{
/**
* @var array
*/
public $params;

public function __construct(...$params)
{
$this->params = $params;
}
}

0 comments on commit 150bd1b

Please sign in to comment.