PHP 8.0 Syntax Showcase

Since RC1 is released today, I decided to make a small demonstration of PHP 8.0 syntax features.

<?php

#[FuncAttribute]
function func(SplHeap|ArrayObject|null $object, mixed $value = null): ArrayAccess|false
{
    return match ($object?->count()) {
        0, null => throw new RuntimeException(),
        default => $object,
    };
}

try {
    func(object: new ArrayObject());
} catch (RuntimeException) {
    // ignore
}

Comments

Comments powered by Disqus