Answer the question
In order to leave comments, you need to log in
The property ... is not readable because it is typed "string". But why?
I used a new php7.4 feature - strict typing of variables, but gives an error
The property "App\Entity\Conference::$slug" is not readable because it is typed "string". You should either initialize it or make it nullable using "?string" instead.
private ?string $slug;
// ...
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
Answer the question
In order to leave comments, you need to log in
Found. For those who run into
this, the reason is that the language designers consider it bad practice to default null to an empty property that they won't support.
private ?string $slug = null;
If a typed property does not have a default value, no implicit null default value is implied (even if the property is nullable). Instead, the property is considered to be uninitialized. Reads from uninitialized properties will generate a TypeErrorhttps://wiki.php.net/rfc/typed_properties_v2#unini...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question