Property cannot be both final and private

Description

When a property is final, it cannot be overridden in a child class; when a class is private, it is only available in the current class.

Hence, a property cannot be final and private at the same time.

In this situation, the property may not final, as there are no property hooks.

Example

<?php

class X {
     final private $property;
}

?>

Solutions

  • Remove the hooks, and use the magic methods __get/__set.

  • Remove the final keyword.

  • Remove the private keyword and use protected or public.

In previous PHP versions, this error message used to be Property cannot be both final and private.