3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @author ciid */ class Variadic { public array $names = []; public function __construct( string ...$names, // ...[string $name => mixed $value], ) { $this->names = $names; } } $var = new Variadic('wan', 'chew', 'tree'); var_dump($var); $json = '{"names":["wan", "chew", "tree"]}'; $obj = json_decode($json); var_dump($obj);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.15, 8.5.0
object(Variadic)#1 (1) { ["names"]=> array(3) { [0]=> string(3) "wan" [1]=> string(4) "chew" [2]=> string(4) "tree" } } object(stdClass)#2 (1) { ["names"]=> array(3) { [0]=> string(3) "wan" [1]=> string(4) "chew" [2]=> string(4) "tree" } }

preferences:
49.13 ms | 412 KiB | 5 Q