Last active
January 3, 2022 16:13
-
-
Save trianglman/f46959308f9551feba286056cc03d9b3 to your computer and use it in GitHub Desktop.
Userland typed JSON deserializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataContainer { | |
public function __construct(public string $param1, public int $param2) | |
{ | |
} | |
public static function fromJson(string $json): self | |
{ | |
return call_user_func_array(fn (string $param1, int $param2) => new self($param1, $param2), json_decode($json, true)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this has a parse error - one too few
)
s on line 8.