Cannot use ‘readonly’ as %s modifier

Description

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

Example

<?php

class X {
    readonly function foo() {}
}

?>

Literal Examples

  • Cannot use 'readonly' as method modifier

  • Cannot use 'readonly' as constant modifier

  • Cannot use 'readonly' as constant modifier

Solutions

  • Remove the readonly option from the method signature.