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

Who Modifies This Property?

<?php

class x {
        function __construct(
            int &$y { get => $this->y; },
        ) {}
}

$w = 4;
$x = new x($w);

Several observations in this code:

it is possible to define a property without visibility: the property hook makes it a promoted property.

It is also possible possible to create a reference on a property, as promoted properties are also an argument.

When all these features are together, it yields an error about accessing an uninitialized property.

See Also

PHP Error Messages

PHP Features

Last updated: 10 September 2026