Get hook of backed property %s::%s with set hook may not return by reference

Description

When a property is a virtual property, the get hook cannot return a reference.

Example

<?php

class A {
    public $prop;
}

class B extends A {
    private $_prop;
    public $prop {
        &get => $this->_prop;
        set { $this->_prop = $value; }
    }
}

?>

Literal Examples

  • Get hook of backed property B::$prop with set hook may not return by reference

Solutions

  • Make the virtual property a concrete one.

  • Remove the reference.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.