Skip to editor
Psalm
Docs
Playground
Plugins
Blog
Paid support
Share
Fix issues
Show original
PHP
Settings
<?php class Http { public const STATUS_OK = 200; public const STATUS_BAD_REQUEST = 400; } /** * @template D * @template S of Http::STATUS_* */ class JsonResponse { /** @var S */ private int $status; /** * @param D $data * @param S $status */ public function __construct($data, int $status) { $this->status = $status; } } class Cat implements JsonSerializable { public function jsonSerialize(): mixed { return 'meow'; } } $rCat200 = new JsonResponse(new Cat(), 200); $rBool400 = new JsonResponse(false, 400); $rBool400Const = new JsonResponse(false, Http::STATUS_BAD_REQUEST); /** * @return JsonResponse<null, 200>|JsonResponse<Cat, 400> */ function getCat(): JsonResponse { if (1+1==2) { return new JsonResponse(null, 200); } else { return new JsonResponse(new Cat(), 400); } } /** * @return JsonResponse<array{'barks': bool}, 400>|JsonResponse<array{'meows': bool}, 200> */ function getPet(): JsonResponse { if (1+1==2) { return new JsonResponse(['meows' => true], 200); } else { return new JsonResponse(['barks' => false], 400); } }
Issues
Types
idle
Saved Feb 14 2023 13:24 UTC
⌘/Ctrl+Enter
run
⌘/Ctrl+S
share
F8
/
⇧F8
next/prev issue