php - PHP 可空类型声明
问题描述
PHP 7.4 中的这个函数有什么区别吗?
public function foo(string $argumentThatCanBeNull = null) {}
public function bar(?string $argumentThatCanBeNull = null) {}
解决方案
没有区别,因为字符串默认可以为空。
顺便说一句,这是在 PHP 7.1 中引入的:https ://www.php.net/manual/en/migration71.new-features.php
推荐阅读
- java - 如何从java打开和关闭pdf文件?
- spring - 服务器启动期间spring托管调度器任务的执行行为
- python - 从包含复数的 .txt 文件中读取列数据的最佳方法是什么?
- sql - SQL 查询到 Json 数据
- homebrew - 为什么 brew 会下载较旧的 bazel 版本
- scala - 表征特征中的协变问题
- python - 在 Seaborn 中为 python 创建一个箱线图 FacetGrid
- c# - 如何在几秒钟后更改标签文本?
- asp.net - ASP.NET MVC - 更改系统日期时,Request.IsAuthenticated 为 false
- .net - 加密 256 字节块大小,哪种算法可以做到这一点?