码迷,mamicode.com
首页 > Web开发 > 详细

php 7 新特性 strict 模式

时间:2017-08-30 18:25:52      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:img   class   col   值类型   foo   技术分享   code   pes   str   

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); //正常
php strict模式开启

 

php 7 新特性 strict 模式

标签:img   class   col   值类型   foo   技术分享   code   pes   str   

原文地址:http://www.cnblogs.com/rcltocode/p/7454418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!