3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php defined('_') or define('_', null); trait ADT { private $args = []; public function __construct(...$args) { $this->args = $args; } public static function __callStatic(string $name, array $args) { $const = static::class . '::' . strtoupper($name); $class = $name . static::class; if (!class_exists($class, true)) { $code = sprintf('final class %s extends %s { use ADT; }', $class, static::class); eval($code); } print_r($args); return new $class(...$args); } } class Gender { use ADT; const SOME = ['value']; const NONE = []; } var_dump(Gender::Some(42)); // match($gender, [ // Some(_) // Other(_) => '' // ])
Output for 7.3.0rc3
Array ( [0] => 42 ) object(SomeGender)#1 (2) { ["args":"SomeGender":private]=> array(1) { [0]=> int(42) } ["args":"Gender":private]=> array(0) { } }