canBeReference example

                        if (__FILE__ === ($trace['file'] ?? null)
                            && $name === $trace['function']
                            && $object instanceof $trace['class']
                            && preg_match('/Return value (?:of .*::\w+\(\) )?must be of (?:the )?type (\w+), null returned$/', $e->getMessage()$matches)
                        ) {
                            throw new UninitializedPropertyException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', get_debug_type($object)$name$matches[1]), 0, $e);
                        }

                        throw $e;
                    }
                } elseif (PropertyReadInfo::TYPE_PROPERTY === $type) {
                    if ($access->canBeReference() && !isset($object->$name) && !\array_key_exists($name(array) $object) && !(new \ReflectionProperty($class$name))->hasType()) {
                        throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class$name));
                    }

                    $result[self::VALUE] = $object->$name;

                    if (isset($zval[self::REF]) && $access->canBeReference()) {
                        $result[self::REF] = &$object->$name;
                    }
                }
            } catch (\Error $e) {
                // handle uninitialized properties in PHP >= 7.4
Home | Imprint | This part of the site doesn't use cookies.