php严格模式的使用
2024-10-20 11:35:53
<?php
declare (strict_types = 1);
namespace app\controller; use app\BaseController;
use think\facade\Db; class Index extends BaseController
{
public function index()
{
$this->hello((int) $_GET['a']);
$a = Db::name('user')->where('id', 1)->find(); return json($a);
} public function hello(string $name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
}
1.declare (strict_types = 1); //开启严格模式,检查参数的类型
Argument 1 passed to app\controller\Index::hello() must be of the type string, int given, called in /www/wwwroot/test/tp6/app/controller/Index.php on line 12
1.传参和定义的类型不一致会直接报错,去掉严格模式不会报错
2.hello(string $name = 'ThinkPHP6') //hello函数定义name必须传字符串类型
3.$this->hello((int) $_GET['a']); //实际传参时候给了一个整形
4.declare (strict_types = 1); 在严格模式下直接报错
最新文章
- android 复制字符串到剪贴板
- wordexpress
- IIS:日志代码分析
- linux+php+apache+mysql(mariadb)故障排除
- Hibernate 的saveOrUpdate方法(转)
- ASP.NET MVC5 插件化机制简单实现
- aspx页面Page_Load和aspx页面上控件Page_Load事件执行顺序
- OSGI.NET 学习笔记--应用篇
- [LeetNode]Sort List
- ASP.Net网站部署失败
- Python 基础-python环境变量、模块初识及字符类型
- css考核点整理(九)-有几种文字替换方式,之间的优缺点
- CentOS安装错误:no default or ui configuration
- BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富( dp )
- 大数据系列修炼-Scala课程02
- windows8.1安装之后的感想
- 安徽省2016“京胜杯”程序设计大赛_E_转啊转
- js的基础要点
- ubuntu10.04 安装配置tftp服务
- VB.NET 泛型类型的应用经验
热门文章
- Smart200 设计注意设计
- react+Native使用typeScript
- 解决CORS跨域问题
- c++练习271题:水仙花数
- 分析网络工具 Wireshark与tcpdump
- React 安装 Sass 错误问题; node-sass 安装运行成功 yarn add sass node-sass@npm:sass
- leecode75. 颜色分类
- vscode 报错command line option ‘-std=c11‘ is valid for C/ObjC but not for C++
- django源码剖析(steup、runserver、生命周期)
- c-->; #define 定义宏