반응형
php(?int)에서 형식 선언 전 물음표(?)는 무엇을 의미합니까?
나는 그들이 ?int를 사용하고 있는 https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Output/Output.php 라인 번호 40에서 이 코드를 보았습니다.
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);
}
라고 합니다.Nullable types
.
다음을 정의합니다.?int
어느 쪽이든int
또는null
.
이제 형식 이름 앞에 물음표를 붙여 매개 변수 및 반환 값에 대한 형식 선언을 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
언급URL : https://stackoverflow.com/questions/49404191/what-does-question-mark-before-type-declaration-means-in-php-int
반응형
'sourcecode' 카테고리의 다른 글
백만 개의 숫자 문자열이 주어지면 반복되는 모든 3자리 숫자를 반환합니다. (0) | 2023.09.05 |
---|---|
jQuery로 바인딩된 이벤트 순서 지정 방법 (0) | 2023.09.05 |
Spring MVC: 여러 URL을 동일한 컨트롤러에 매핑 (0) | 2023.09.05 |
파워셸에서 TDD 및 유닛 테스트를 수행하는 방법은 무엇입니까? (0) | 2023.08.31 |
날짜를 페르시아어로 변환하기 위한 Oracle 함수 작성 방법(잘라리) (0) | 2023.08.31 |