3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Subject { // valid return types public function int(): int; public function bool(): bool; public function array(): array; public function float(): float; public function string(): string; public function iterable(): iterable; public function callable(): callable; public function void(): void; public function object(): object; public function mixed(): mixed; // invalid return types public function self(): self; public function integer(): integer; public function boolean(): boolean; public function double(): double; public function resource(): resource; } interface Subject2 { // valid return types PUBLIC FUNCTION INT(): INT; PUBLIC FUNCTION BOOL(): BOOL; PUBLIC FUNCTION ARRAY(): ARRAY; PUBLIC FUNCTION FLOAT(): FLOAT; PUBLIC FUNCTION STRING(): STRING; PUBLIC FUNCTION ITERABLE(): ITERABLE; PUBLIC FUNCTION CALLABLE(): CALLABLE; PUBLIC FUNCTION VOID(): VOID; PUBLIC FUNCTION OBJECT(): OBJECT; PUBLIC FUNCTION MIXED(): MIXED; PUBLIC FUNCTION SELF(): SELF; // invalid return types PUBLIC FUNCTION INTEGER(): INTEGER; PUBLIC FUNCTION BOOLEAN(): BOOLEAN; PUBLIC FUNCTION DOUBLE(): DOUBLE; PUBLIC FUNCTION RESOURCE(): RESOURCE; } test(Subject::class); test(Subject2::class); /** * @param class-string $class */ function test(string $class): void { $result = []; $ref = new ReflectionClass($class); foreach ($ref->getMethods() as $ref_method) { $name = $ref_method->getName(); $type = $ref_method->getReturnType(); $is_valid = $type instanceof ReflectionNamedType && $type->isBuiltin(); $key = $is_valid ? 'valid' : 'invalid'; $type_name = $type instanceof ReflectionNamedType ? $type->getName() : null; if ($type_name && $name !== $type_name) { $name = "{$name} -> {$type_name}"; } $result[$key][] = $name; } echo $class, ' ', json_encode($result, JSON_PRETTY_PRINT), PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
Warning: "integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning in /in/fJgLA on line 19 Warning: "boolean" will be interpreted as a class name. Did you mean "bool"? Write "\boolean" to suppress this warning in /in/fJgLA on line 20 Warning: "double" will be interpreted as a class name. Did you mean "float"? Write "\double" to suppress this warning in /in/fJgLA on line 21 Warning: "resource" is not a supported builtin type and will be interpreted as a class name. Write "\resource" to suppress this warning in /in/fJgLA on line 22 Subject { "valid": [ "int", "bool", "array", "float", "string", "iterable", "callable", "void", "object", "mixed" ], "invalid": [ "self", "integer", "boolean", "double", "resource" ] } Subject2 { "valid": [ "INT -> int", "BOOL -> bool", "ARRAY -> array", "FLOAT -> float", "STRING -> string", "ITERABLE -> iterable", "CALLABLE -> callable", "VOID -> void", "OBJECT -> object", "MIXED -> mixed" ], "invalid": [ "SELF", "INTEGER", "BOOLEAN", "DOUBLE", "RESOURCE" ] }

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:
29.86 ms | 409 KiB | 5 Q