8000 [PropertyAccess] Improve message of unitialized property in php 7.4 · symfony/symfony@3c8bf2d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c8bf2d

Browse files
lmasfornefabpot
authored andcommitted
[PropertyAccess] Improve message of unitialized property in php 7.4
1 parent 5da141b commit 3c8bf2d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private function readProperty($zval, $property)
505505
if (\PHP_VERSION_ID >= 70400 && preg_match('/^Typed property ([\w\\\]+)::\$(\w+) must not be accessed before initialization$/', $e->getMessage(), $matches)) {
506506
$r = new \ReflectionProperty($matches[1], $matches[2]);
507507

508-
throw new AccessException(sprintf('The property "%s::$%s" is not readable because it is typed "%3$s". You should either initialize it or make it nullable using "?%3$s" instead.', $r->getDeclaringClass()->getName(), $r->getName(), $r->getType()->getName()), 0, $e);
508+
throw new AccessException(sprintf('The property "%s::$%s" is not readable because it is typed "%2$s". You should initialize it or declare a default value instead.', $r->getDeclaringClass()->getName(), $r->getType()->getName()), 0, $e);
509509
}
510510

511511
throw $e;

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 1 addition & 1 deletion
{
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnab
126126
public function testGetValueThrowsExceptionIfUninitializedProperty()
127127
128128
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
129-
$this->expectExceptionMessage('The property "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedProperty::$uninitialized" is not readable because it is typed "string". You should either initialize it or make it nullable using "?string" instead.');
129+
$this->expectExceptionMessage('The property "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedProperty::$uninitialized" is not readable because it is typed "string". You should initialize it or declare a default value instead.');
130130

131131
$this->propertyAccessor->getValue(new UninitializedProperty(), 'uninitialized');
132132
}

0 commit comments

Comments
 (0)
0