3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Foo { public const CONSTANT = 1; public function bar(): int { return self::CONSTANT; // Fatal error } } class Bar { use Foo; } var_dump(Bar::CONSTANT); // 1 $bar = new Bar(); $bar->bar();
Output for 8.2.21 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.17, 8.5.0 - 8.5.2
int(1)
Output for 8.0.1 - 8.0.26, 8.1.0 - 8.1.34
Fatal error: Traits cannot have constants in /in/dIeOk on line 5
Process exited with code 255.

preferences:
103.02 ms | 407 KiB | 5 Q