3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); #[Attribute(Attribute::TARGET_PROPERTY)] class TestAttribute { public function __construct( public $callback ) {} } final class Clock { public function format(string $format): string { return $format; } } final class Example { // This version FAILS (Fatal error: Constant expression contains invalid operations) //#[TestAttribute(static fn (Clock $clock) => $clock->format('Y-m-d H:i:s'))] // This version PASSES #[TestAttribute(static function (Clock $clock) { return $clock->format('Y-m-d H:i:s'); })] public ?Clock $created_at = null; } $ref = new ReflectionProperty(Example::class, 'created_at'); $attr = $ref->getAttributes(TestAttribute::class)[0]->newInstance(); var_dump($attr->callback instanceof Closure);
Output for git.master_jit
bool(true)
Output for git.master

Process exited with code 139.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.99 ms | 492 KiB | 3 Q