3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { public const TOTO = 'cocou'; protected $foo = []; public function set($a) { $this->foo[$a::TOTO] = 'Totot'; } } $a = 'A'; $o= new A(); $o->set($a); var_dump($o);
based on JZNYN
Output for 7.1.0 - 7.3.0beta1
object(A)#1 (1) { ["foo":protected]=> array(1) { ["cocou"]=> string(5) "Totot" } }
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.0.20
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/XD7hf on line 5
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected T_CONST, expecting T_VARIABLE in /in/XD7hf:5 Stack trace: #0 {main}
Process exited with code 255.