3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Database {} $fns = [ function ($str) {}, function ($str ="hello") {}, function (string $str) {}, function (string $str = null) {}, function (?string $str) {}, function (?Database $db) {}, function (Database $db = new Database()) {}, function (string|null $str) {}, function (string $str = "hello") {}, function (?string $str = "hello") {}, function (string|int $str) {}, function (string|null $str = null) {}, function (string|null $str = "hello") {}, ]; echo "parameter\tallowsNull\tisOptional\tgetDefaultValue\tgetType\n"; foreach ($fns as $fn) { $param = (new ReflectionFunction($fn))->getParameters()[0]; echo substr($param->__toString(), 26, -2) . "\t" . json_encode($param->allowsNull()) . "\t" . json_encode($param->isOptional()) . "\t" . ($param->isDefaultValueAvailable() ? str_replace("\n", "", print_r($param->getDefaultValue(), true)) : "throws ReflectionException") . "\t" . ($param->getType() ? get_class($param->getType()) : "null") . "\n"; }
Output for git.master_jit, git.master
Deprecated: {closure:/in/pnXfM:9}(): Implicitly marking parameter $str as nullable is deprecated, the explicit nullable type must be used instead in /in/pnXfM on line 9 parameter allowsNull isOptional getDefaultValue getType $str true false throws ReflectionException null $str = 'hello' true true hello null string $str false false throws ReflectionException ReflectionNamedType ?string $str = NULL true true ReflectionNamedType ?string $str true false throws ReflectionException ReflectionNamedType ?Database $db true false throws ReflectionException ReflectionNamedType Database $db = new \Database() false true Database Object() ReflectionNamedType ?string $str true false throws ReflectionException ReflectionNamedType string $str = 'hello' false true hello ReflectionNamedType ?string $str = 'hello' true true hello ReflectionNamedType string|int $str false false throws ReflectionException ReflectionUnionType ?string $str = NULL true true ReflectionNamedType ?string $str = 'hello' true true hello ReflectionNamedType

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
75.99 ms | 408 KiB | 5 Q