3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[AllowDynamicProperties] class Scratch_1 { } $new = new Scratch_1(); $prop = 'Content-Type'; $new->$prop = 'application/json'; var_dump($new->$prop); // string(16) "application/json" var_dump($new->{'Content-Type'}); $$prop = 'application/json'; var_dump($$prop); // string(16) "application/json" $prop = '10xl'; $new->$prop = '10xl'; var_dump($new->$prop); // string(3) "10xl" var_dump($new); var_dump(get_defined_vars()['Content-Type']); var_dump(${"Content-Type"});
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
string(16) "application/json" string(16) "application/json" string(16) "application/json" string(4) "10xl" object(Scratch_1)#1 (2) { ["Content-Type"]=> string(16) "application/json" ["10xl"]=> string(4) "10xl" } string(16) "application/json" string(16) "application/json"

preferences:
78.57 ms | 407 KiB | 5 Q