Skip to content

Commit fa39a0e

Browse files
committed
PhpReflection::getParameterType() supports type 'self'
1 parent 92f0fdd commit fa39a0e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/DI/PhpReflection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public static function getDeclaringClass(\ReflectionProperty $prop)
5959
public static function getParameterType(\ReflectionParameter $param)
6060
{
6161
if (PHP_VERSION_ID >= 70000) {
62-
return $param->hasType() ? (string) $param->getType() : NULL;
62+
$type = $param->hasType() ? (string) $param->getType() : NULL;
63+
return strtolower($type) === 'self' ? $param->getDeclaringClass()->getName() : $type;
6364
} elseif ($param->isArray() || $param->isCallable()) {
6465
return $param->isArray() ? 'array' : 'callable';
6566
} else {

tests/DI/Helpers.autowireArguments.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class Container
2121

2222
class Test
2323
{
24-
function method(Test $class, Undefined $nullable1 = NULL, int $nullable2 = NULL)
24+
function method(Test $class, self $self, Undefined $nullable1 = NULL, int $nullable2 = NULL)
2525
{}
2626
}
2727

2828
$container = new Container;
2929

3030
Assert::equal(
31-
[new Test],
31+
[new Test, new Test],
3232
Helpers::autowireArguments(new ReflectionMethod('Test', 'method'), [], $container)
3333
);

0 commit comments

Comments
 (0)