3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=0); function acceptBool(bool $x) {} function acceptInt(int $x) {} function acceptFloat(float $x) {} function acceptString(string $x) {} function acceptArray(array $x) {} function acceptObject(object $x) {} $functions = [ "bool" => "acceptBool", "int" => "acceptInt", "float" => "acceptFloat", "string" => "acceptString", "array" => "acceptArray", "object" => "acceptObject", ]; $vars = [ "null" => null, "bool" => true, "int" => 1, "float" => 3.14, "numeric string" => "2.72", "non-numeric string" => "elephphant", "array" => [1, 2, 3], "object" => new stdClass(), ]; foreach ($vars as $passedType => $var) { foreach ($functions as $acceptedType => $function) { if ($passedType === $acceptedType) { continue; } echo str_pad($passedType, 18) . " -> " . str_pad($acceptedType, 10) . ": "; try { $function($var); echo "success"; } catch(TypeError $e) { echo "failure"; } echo "\n"; } }
Output for git.master, git.master_jit, rfc.property-hooks
null -> bool : failure null -> int : failure null -> float : failure null -> string : failure null -> array : failure null -> object : failure bool -> int : success bool -> float : success bool -> string : success bool -> array : failure bool -> object : failure int -> bool : success int -> float : success int -> string : success int -> array : failure int -> object : failure float -> bool : success float -> int : Deprecated: Implicit conversion from float 3.14 to int loses precision in /in/lSGSr on line 6 success float -> string : success float -> array : failure float -> object : failure numeric string -> bool : success numeric string -> int : Deprecated: Implicit conversion from float-string "2.72" to int loses precision in /in/lSGSr on line 6 success numeric string -> float : success numeric string -> string : success numeric string -> array : failure numeric string -> object : failure non-numeric string -> bool : success non-numeric string -> int : failure non-numeric string -> float : failure non-numeric string -> string : success non-numeric string -> array : failure non-numeric string -> object : failure array -> bool : failure array -> int : failure array -> float : failure array -> string : failure array -> object : failure object -> bool : failure object -> int : failure object -> float : failure object -> string : failure object -> array : failure

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:
26.13 ms | 411 KiB | 5 Q