---
date: 2020-11-09
id: cb0583f2-374c-4788-b826-dbb7e5903711
title: PHP Union Type
---

# Description

Allows multiple possible types\[fn:rc\] to be given to a
parameter/member.

# Syntax

``` php
class Example {
    private int|float $foo;

    public function __construct(int|float $foo) {
        $this->foo = $foo;
    }

    public function doSomethingWithMultipleTypes(float|int $bar): int|float {
        return ($bar + $this->foo) * 2;
    }
}
```

# Inheritance

``` php
class A{
    public function foo(string|int $foo): string|int {}
}

class B extends A{
    public function foo(string|int|float $foo): string {}
}
```

# Footnotes
