Cannot use ‘readonly’ as method modifier

Description

readonly is reserved for properties, and cannot be used with methods, constants, enumeration cases or static properties.

Example

<?php

class X {
     private readonly function foo() {}
}

?>

Solutions

  • Remove the option from the method signature.