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 ‘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

Alternatives

  • Remove the readonly option from the method signature.