Skip to content

Commit e347e41

Browse files
committed
bug symfony#32466 [Config] Fix for signatures of typed properties (tvandervorm)
This PR was submitted for the 4.3 branch but it was squashed and merged into the 3.4 branch instead (closes symfony#32466). Discussion ---------- [Config] Fix for signatures of typed properties | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#32465 | License | MIT | Doc PR | - Also see the issue description, when using public typed properties ([new in PHP7.4](https://wiki.php.net/rfc/typed_properties_v2)) like this: ``` namespace App; class Foo { public int $bar; } ``` will cause `$defaults['bar']` not to be set in Symfony/Component/Config/Resource/ReflectionClassResource.php::139. This is because `$bar` doesn't have a default value, but does have a type hint, meaning it's default value is not `null` but undefined. This causes an 'undefined index' error when clearing the cache through `bin/console cache:clear` when running PHP7.4. The default value is used here for the class signature, having `null` should be appropriate for all cases. Commits ------- bad2a2c [Config] Fix for signatures of typed properties
2 parents 0825ea7 + bad2a2c commit e347e41

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function generateSignature(\ReflectionClass $class)
140140

141141
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
142142
yield $p->getDocComment().$p;
143-
yield print_r($defaults[$p->name], true);
143+
yield print_r($defaults[$p->name] ?? null, true);
144144
}
145145
}
146146

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ public function provideHashedSignature()
137137
yield [1, 13, 'protected function prot($a = [123]) {}'];
138138
yield [0, 14, '/** priv docblock */'];
139139
yield [0, 15, ''];
140+
141+
if (\PHP_VERSION_ID >= 70400) {
142+
// PHP7.4 typed properties without default value are
143+
// undefined, make sure this doesn't throw an error
144+
yield [1, 5, 'public array $pub;'];
145+
yield [0, 7, 'protected int $prot;'];
146+
yield [0, 9, 'private string $priv;'];
147+
}
140148
}
141149

142150
public function testEventSubscriber()

0 commit comments

Comments
 (0)