You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (preg_match((sprintf('/Return value of %s::%s\(\) must be of the type (\w+), null returned/', preg_quote(\get_class($object)), $access[self::ACCESS_NAME])), $e->getMessage(), $matches)) {
475
+
thrownewAccessException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Have you forgotten to initialize a property or to make the return type nullable using "?%3$s" instead?', \get_class($object), $access[self::ACCESS_NAME], $matches[1]), 0, $e);
// Needed to support \stdClass instances. We need to explicitly
478
-
// exclude $access[self::ACCESS_HAS_PROPERTY], otherwise if
479
-
// a *protected* property was found on the class, property_exists()
480
-
// returns true, consequently the following line will result in a
481
-
// fatal error.
503
+
} catch (\Error$e) {
504
+
// handle uninitialized properties in PHP >= 7.4
505
+
if (preg_match(sprintf('/Typed property %s::\$(\w+) must not be accessed before initialization/', preg_quote(\get_class($object))), $e->getMessage(), $matches)) {
506
+
$r = new \ReflectionProperty(\get_class($object), $matches[1]);
482
507
483
-
$result[self::VALUE] = $object->$property;
484
-
if (isset($zval[self::REF])) {
485
-
$result[self::REF] = &$object->$property;
508
+
thrownewAccessException(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()), 0, $e);
$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.');
$this->expectExceptionMessage('The method "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty::getUninitialized()" returned "null", but expected type "array". Have you forgotten to initialize a property or to make the return type nullable using "?array" instead?');
0 commit comments