php7的新特性 declare(strict_types=1);
强类型strict_types是从PHP7开始才引入的东西,默认不开启
strict_types=1无非就是约束了参数和返回值的类型

<?php declare(strict_types=1); function foo(int $num): int { return $num/2; } foo(1); //返回值类型错误 foo(1.5); //参数类型错误 foo(2); //正常
php7的新特性 declare(strict_types=1);
强类型strict_types是从PHP7开始才引入的东西,默认不开启
strict_types=1无非就是约束了参数和返回值的类型
<?php declare(strict_types=1); function foo(int $num): int { return $num/2; } foo(1); //返回值类型错误 foo(1.5); //参数类型错误 foo(2); //正常
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。