php图片写入带问号_PHP方法参数类型提示带问号(?type)

I just felt on pieces of php (symfony/laravel) code using question mark in method type hints :

public function functionName(?int $arg = 0)

In other occasions the ?type was not the last one, but I did not find any of these with no default yet.

Problem is, I cannot find any information about this, and I checked :

And same with 7.2, but since the code only requires 7.1, it seems rather normal.

I also googled, and searched here, but either this is not documented or the question marks topic is defeating search engines.

So I feel a little dumb now, and I would really appreciate if someone could enlighten me on the signification of this question mark in method signatures arguments.

Thanks

解决方案

It's a new feature in php7.1

A question mark means that the type hinted parameter (or return value) is also allowed to be null.

So in your example $arg can be null or any integer.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值