Must not use parent::$%s::%s() in a different property hook (%s)

Description

Property hooks are actual methods: they can call other methods to fulfill their mission. They may also call the parent’ methods, and, as such, they may also call the parent’s property hook. This has lead to the syntax parent::$properpty::get().

This syntax is specific to property hooks, and can only be used inside the same property hook for the same property.

Example

<?php

class X {
    public string $q {
        get => 'in parent';
    }
}

class Y extends X {
    public string $q {
        // Must not use parent::$q::get() in a different property hook ($p)
        set => parent::$q::get();
    }
}

$y = new Y;
echo $y->q;

?>

Literal Examples

  • Must not use parent::$q::get() in a different property hook ($p)

Solutions

  • Move the block of the property hook in a regular method and call it from the hook and other methods.

  • Inline the code every time it is needed.