No Property In Interface

<?php

function naturalIntegers() {
    $i = 0;
    while (true) {
        yield $i++;
    }
}

foreach(naturalIntegers() as $i) {
    if ($i > 10) {
        break;
    }
    print $i.PHP_EOL;
}

print "finished
";

PHP is better than me : I thought I found a way to create properties in an interface, by declaring promoted properties in a constructor.

Someone coding the PHP engine was smarter than me : it feels so good! (BTW, who would that be?)

It’s also going to save me some sanity, as I don’t have to upgrade my Static Analysis Engine.

Note that PHP 8.4 introduced properties in interfaces, as long as they have property hooks.

See Also

PHP Features

Last updated: 14 July 2026