Indirect modification of %s::$%s is not allowed

Description

While it is possible to create references on object’s properties, it is not possible to do so on a property with a hook. The property hook is returned by value, by default.

Example

<?php

class X {
    public $byRef {
        get {
            $x = 42;
            return $x;
        }
    }
}

$x = new x;
$y = &$x->byRef;

?>

Solutions

  • Add & before the get hook.

  • Make the property a normal property, without hooks.

  • Avoid using a reference on a property hook.