%s virtual property %s::$%s must not specify asymmetric visibility

Description

A virtual property is related to property hooks: it is a property whose hook do not use the underlying property for storage, but uses another one (or, like here, none).

When the set or get visibility doesn’t apply, this error is displayed. The error message may start with Read-only or Write-only.

Example

<?php

class X {
     public private(set) int $p {
             set {}
     }
}

class Y {
     public private(set) int $p {
             get {}
     }
}

?>

Literal Examples

  • Write-only virtual property X::$p must not specify asymmetric visibility

  • Readonly-only virtual property Y::$p must not specify asymmetric visibility

Solutions

  • Remove the asymmetric visibility from the definition of the property.

  • Remove the property hook from the definition of the property.

  • Remove the virtual property, by making the property hook use the underlying property.