Type hint in PHP function parameters and return values, properties and constants

Function parameters and return types:

array

function foo(array $bar)PHP 5.1+example
function foo(array $bar = null)PHP 5.1+example
function foo(?array $bar)PHP 7.1+example
function foo(): arrayPHP 7.0+example
function foo(): ?arrayPHP 7.1+example

bool

function foo(bool $bar)PHP 7.0+example
function foo(bool $bar = null)PHP 7.0+example
function foo(?bool $bar)PHP 7.1+example
function foo(): boolPHP 7.0+example
function foo(): ?boolPHP 7.1+example

callable

function foo(callable $bar)PHP 5.4+example
function foo(callable $bar = null)PHP 5.4+example
function foo(?callable $bar)PHP 7.1+example
function foo(): callablePHP 7.0+example
function foo(): ?callablePHP 7.1+example

float

function foo(float $bar)PHP 7.0+example
function foo(float $bar = null)PHP 7.0+example
function foo(?float $bar)PHP 7.1+example
function foo(): floatPHP 7.0+example
function foo(): ?floatPHP 7.1+example

int

function foo(int $bar)PHP 7.0+example
function foo(int $bar = null)PHP 7.0+example
function foo(?int $bar)PHP 7.1+example
function foo(): intPHP 7.0+example
function foo(): ?intPHP 7.1+example

iterable

function foo(iterable $bar)PHP 7.1+example
function foo(iterable $bar = null)PHP 7.1+example
function foo(?iterable $bar)PHP 7.1+example
function foo(): iterablePHP 7.1+example
function foo(): ?iterablePHP 7.1+example

object

function foo(object $bar)PHP 7.2+example
function foo(object $bar = null)PHP 7.2+example
function foo(?object $bar)PHP 7.2+example
function foo(): objectPHP 7.2+example
function foo(): ?objectPHP 7.2+example

self

function foo(self $bar)PHP 5.0+example
function foo(self $bar = null)PHP 5.1+example
function foo(?self $bar)PHP 7.1+example
function foo(): selfPHP 7.0+example
function foo(): ?selfPHP 7.1+example

string

function foo(string $bar)PHP 7.0+example
function foo(string $bar = null)PHP 7.0+example
function foo(?string $bar)PHP 7.1+example
function foo(): stringPHP 7.0+example
function foo(): ?stringPHP 7.1+example

class names

function foo(ClassName $bar)PHP 5.0+example
function foo(ClassName $bar = null)PHP 5.1+example
function foo(?ClassName $bar)PHP 7.1+example
function foo(): ClassNamePHP 7.0+example
function foo(): ?ClassNamePHP 7.1+example

void

function foo(): voidPHP 7.1+example

boolean, double, integer, resource, static

Never recognized as valid for type hintingexample 1
example 2
example 3

Class constants

visibility

const NAME = '...';PHP 5.0+example
private const NAME = '...';PHP 7.1+example
protected const NAME = '...';PHP 7.1+example
public const NAME = '...';PHP 7.1+example

types

const string NAME = '...';PHP 8.3+example

Class properties

visibility

var $name = '...';PHP 4.3+example
private $name = '...';PHP 5.0+example
protected $name = '...';PHP 5.0+example
public $name = '...';PHP 5.0+example

types

public string $name = '...';PHP 7.4+example
public ?string $name = '...';PHP 7.4+example