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刪除。