3v4l.org

run code in 500+ 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.31, 8.3.5 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
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:
58.08 ms | 919 KiB | 4 Q