我在他们使用的第40行的https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Output/Output.php中看到过这段代码。
public function __construct(?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null)
{
$this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
$this->formatter = $formatter ?: new OutputFormatter();
$this->formatter->setDecorated($decorated);
}发布于 2018-03-21 18:46:08
它被称为Nullable types。
它将?int定义为int或null。
参数和返回值的
类型声明现在可以通过在类型名称前加上问号来标记为可空。这表示NULL和指定的类型一样,可以作为参数传递,也可以作为值返回。
示例:
function nullOrInt(?int $arg){
var_dump($arg);
}
nullOrInt(100);
nullOrInt(null);函数nullOrInt将同时接受null和int。
参考:http://php.net/manual/en/migration71.new-features.php
https://stackoverflow.com/questions/49404191
复制相似问题