Level 102
You cannot set a property dynamically outside of a method.
public function foo()
{
$this->errorBag = $this->isMethod('patch') ? 'visit' . $this->visit->id : 'new';
}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to conditionally set $errorBag property inside Form Request:
protected $errorBag = $this->isMethod('patch') ? 'visit' . $this->visit->id : 'new';
but it gives me this error:
Constant expression contains invalid operations
Is there any way to do this?
You cannot set a property dynamically outside of a method.
public function foo()
{
$this->errorBag = $this->isMethod('patch') ? 'visit' . $this->visit->id : 'new';
}
Please or to participate in this conversation.