withinboredom/null-cast

类型转换,但带有空值!

v1.0.0 2024-01-27 12:39 UTC

This package is auto-updated.

Last update: 2024-09-27 14:04:00 UTC


README

当使用严格类型时,在类型转换过程中,null 值通常会丢失,从而引入细微的错误。此库允许您使用这些简单的函数替换您的转换,这些函数保留 null 值,但执行所需的转换。

安装

composer require withinboredom/null-cast

使用

use function Withinboredom\NullCast\boolval;
use function Withinboredom\NullCast\floatval;
use function Withinboredom\NullCast\intval;
use function Withinboredom\NullCast\stringval;

boolval('true') === true;
boolval(null) === null;

floatval('12.34') === 12.34;
floatval(null) === null;

intval(true) === 1;
intval(null) === null;

stringval(123) === '123';
stringval(null) === null;