Psalm
Get started
Documentation
Paid support
Plugins
Blog
GitHub
<?php function getIntOrStringOrBool(): int|string|bool { throw new RuntimeException('???'); } function first(): void { $intOrStringOrBool = getIntOrStringOrBool(); if (is_int($intOrStringOrBool)) { /** @psalm-check-type-exact $intOrStringOrBool = int */ } else { /** @psalm-check-type-exact $intOrStringOrBool = string|bool */ } } function second(): void { $intOrStringOrBool = getIntOrStringOrBool(); if (is_int($intOrStringOrBool)) { /** @psalm-check-type-exact $intOrStringOrBool = int */ } elseif (is_string($intOrStringOrBool)) { /** @psalm-check-type-exact $intOrStringOrBool = string */ } else { /** @psalm-check-type-exact $intOrStringOrBool = bool */ } } function third(): void { $intOrStringOrBool = getIntOrStringOrBool(); if (is_int($intOrStringOrBool)) { /** @psalm-check-type-exact $intOrStringOrBool = int */ } elseif (is_string($intOrStringOrBool)) { /** @psalm-check-type-exact $intOrStringOrBool = string */ } elseif (is_bool($intOrStringOrBool)) { // of course it's redundant) /** @psalm-check-type-exact $intOrStringOrBool = bool */ } }
Snippet created on May 31 2023 at 08:21 UTC
Settings
Get link