Cannot override final property hook %s::%s()

Description

Property hooks may be declared final, just like any other methods. In that case, it is not possible to override then with a new definition in a child class.

The property may be declared final as whole, in the property definition; otherwise, each individual hook may be declared final.

Example

<?php

class X {
     public $property {
             final get => 2;
             set => $this->property = $value;
     }
     // No hook can be changed
     public final $q {
             get => 2;
     }
}

class Y extends X {
     public final $property {
             get => 3;                 // This one cannot be overriden
             set => $this->property = $value; // This one is OK
     }
     public final $q {
             get => 2;
     }
}

?>

Literal Examples

  • Cannot override final property hook $p::get()

Solutions

  • Remove the final keyword on the parent hook.

  • Remove the hook in the child class.