Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cannot use the final modifier on a parameter

Description

The final option is not available for promoted properties, until PHP 8.5. Until then, the property shall be final but not promoted, or it has to be declared the traditional way.

Example

<?php

class X {
    function __construct( 
        public final int $i
    ) {}
}

?>

Alternatives

  • Upgrade to PHP 8.5 or more recent.
  • Remove the final property from the promoted property.
  • Create the property in the class body.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See