0

In php, what do the question marks mean in this function signature?

private static function getBooleanAnnotationSetting(string $className, ?string $methodName, string $settingName): ?bool {
}
Tarek Adam
  • 3,387
  • 3
  • 27
  • 52
  • I'm kinda wondering if I pulled a bad composer package. – Tarek Adam Feb 21 '18 at 03:28
  • See also https://stackoverflow.com/a/48450841/9193372 – Syscall Jan 30 '22 at 08:57
  • It's great that we all keep stackoverflow clean, but I'm going to leave this Q/A pair up because it's easy to find. People who don't know what the question mark means - we aren't going to be searching for "nullable". Sorry. – Tarek Adam Feb 01 '22 at 13:26

1 Answers1

1

The question mark represents a nullable type:

Type declarations for parameters and return values can now be marked as nullable by prefixing the type name with a question mark. This signifies that as well as the specified type, NULL can be passed as an argument, or returned as a value, respectively.

This allows you to provision null as an argument without receiving a TypeError.

Marty
  • 39,033
  • 19
  • 93
  • 162